X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Futil.c;h=f1a7bbdc7124b1d977d536fcb4c83bea80213478;hp=4e371d148e34759697fca5a3fbdaa45dcf5f9372;hb=1afbdcb06b2333c1f5852c049bd5e73b729aa6f0;hpb=e51bc1a23e8f581e4fe46aa4df1bd93b7042c184 diff --git a/src/util.c b/src/util.c index 4e371d148..f1a7bbdc7 100644 --- a/src/util.c +++ b/src/util.c @@ -1,4 +1,4 @@ -/*-*- Mode: C; c-basic-offset: 8 -*-*/ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ /*** This file is part of systemd. @@ -48,6 +48,7 @@ #include #include #include +#include #include "macro.h" #include "util.h" @@ -56,6 +57,7 @@ #include "log.h" #include "strv.h" #include "label.h" +#include "exit-status.h" bool streq_ptr(const char *a, const char *b) { @@ -2397,6 +2399,16 @@ bool is_clean_exit(int code, int status) { return false; } +bool is_clean_exit_lsb(int code, int status) { + + if (is_clean_exit(code, status)) + return true; + + return + code == CLD_EXITED && + (status == EXIT_NOTINSTALLED || status == EXIT_NOTCONFIGURED); +} + bool is_device_path(const char *path) { /* Returns true on paths that refer to a device, either in @@ -2492,18 +2504,6 @@ char* gethostname_malloc(void) { return strdup(u.sysname); } -int getmachineid_malloc(char **b) { - int r; - - assert(b); - - if ((r = read_one_line_file("/var/lib/dbus/machine-id", b)) < 0) - return r; - - strstrip(*b); - return 0; -} - char* getlogname_malloc(void) { uid_t uid; long bufsize; @@ -2542,11 +2542,12 @@ char* getlogname_malloc(void) { int getttyname_malloc(char **r) { char path[PATH_MAX], *p, *c; + int k; assert(r); - if (ttyname_r(STDIN_FILENO, path, sizeof(path)) < 0) - return -errno; + if ((k = ttyname_r(STDIN_FILENO, path, sizeof(path))) != 0) + return -k; char_array_0(path); @@ -2991,6 +2992,31 @@ char *ellipsize(const char *s, unsigned length, unsigned percent) { return r; } +int touch(const char *path) { + int fd; + + assert(path); + + if ((fd = open(path, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY, 0666)) < 0) + return -errno; + + close_nointr_nofail(fd); + return 0; +} + +char *unquote(const char *s, const char quote) { + size_t l; + assert(s); + + if ((l = strlen(s)) < 2) + return strdup(s); + + if (s[0] == quote && s[l-1] == quote) + return strndup(s+1, l-2); + + return strdup(s); +} + static const char *const ioprio_class_table[] = { [IOPRIO_CLASS_NONE] = "none", [IOPRIO_CLASS_RT] = "realtime",