chiark / gitweb /
mount: properly handle LABEL="" in fstab
[elogind.git] / src / util.c
index c0b63dd574ba911a4d9f282d5184a21785a8fbb6..f1a7bbdc7124b1d977d536fcb4c83bea80213478 100644 (file)
@@ -57,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) {
 
@@ -2398,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
@@ -2531,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);
 
@@ -2980,23 +2992,30 @@ char *ellipsize(const char *s, unsigned length, unsigned percent) {
         return r;
 }
 
-void nss_disable_nscd(void) {
+int touch(const char *path) {
+        int fd;
 
-        void (*func)(void);
+        assert(path);
 
-        /* This is an internal glibc function call. We are not
-         * supposed to call this, because we are not nscd. However
-         * sometimes we feel really dangerous and do it
-         * nonetheless. Muahahah! But at least we protect this with a
-         * dlsym() just in case glibc takes this away from us. */
+        if ((fd = open(path, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY, 0666)) < 0)
+                return -errno;
 
-        if ((func = dlsym(RTLD_DEFAULT, "__nss_disable_nscd"))) {
-                log_debug("Disabling nscd.");
-                func();
-        } else
-                log_debug("Cannot disable nscd.");
+        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",