chiark / gitweb /
swap: don't add mount links for swap devices
[elogind.git] / util.c
diff --git a/util.c b/util.c
index 8556ea12cd153d6899f3b98a8cc803e80b61f401..f7d538aaacf87496367661ba3822bc2f44cb6070 100644 (file)
--- a/util.c
+++ b/util.c
@@ -42,6 +42,7 @@
 #include <sys/inotify.h>
 #include <sys/poll.h>
 #include <libgen.h>
+#include <ctype.h>
 
 #include "macro.h"
 #include "util.h"
@@ -141,6 +142,30 @@ bool startswith(const char *s, const char *prefix) {
         return memcmp(s, prefix, pl) == 0;
 }
 
+bool startswith_no_case(const char *s, const char *prefix) {
+        size_t sl, pl;
+        unsigned i;
+
+        assert(s);
+        assert(prefix);
+
+        sl = strlen(s);
+        pl = strlen(prefix);
+
+        if (pl == 0)
+                return true;
+
+        if (sl < pl)
+                return false;
+
+        for(i = 0; i < pl; ++i) {
+                if (tolower(s[i]) != tolower(prefix[i]))
+                        return false;
+        }
+
+        return true;
+}
+
 bool first_word(const char *s, const char *word) {
         size_t sl, wl;
 
@@ -1199,6 +1224,7 @@ bool ignore_file(const char *filename) {
 
         return
                 filename[0] == '.' ||
+                streq(filename, "lost+found") ||
                 endswith(filename, "~") ||
                 endswith(filename, ".rpmnew") ||
                 endswith(filename, ".rpmsave") ||
@@ -1333,7 +1359,9 @@ bool fstype_is_network(const char *fstype) {
                 "smbfs",
                 "ncpfs",
                 "nfs",
-                "nfs4"
+                "nfs4",
+                "gfs",
+                "gfs2"
         };
 
         unsigned i;
@@ -1571,7 +1599,7 @@ int flush_fd(int fd) {
 }
 
 int acquire_terminal(const char *name, bool fail, bool force) {
-        int fd = -1, notify = -1, r, wd;
+        int fd = -1, notify = -1, r, wd = -1;
 
         assert(name);
 
@@ -1601,8 +1629,9 @@ int acquire_terminal(const char *name, bool fail, bool force) {
         }
 
         for (;;) {
-                if ((r = flush_fd(notify)) < 0)
-                        goto fail;
+                if (notify >= 0)
+                        if ((r = flush_fd(notify)) < 0)
+                                goto fail;
 
                 /* We pass here O_NOCTTY only so that we can check the return
                  * value TIOCSCTTY and have a reliable way to figure out if we
@@ -1863,6 +1892,51 @@ int parse_usec(const char *t, usec_t *usec) {
         return 0;
 }
 
+int make_stdio(int fd) {
+        int r, s, t;
+
+        assert(fd >= 0);
+
+        r = dup2(fd, STDIN_FILENO);
+        s = dup2(fd, STDOUT_FILENO);
+        t = dup2(fd, STDERR_FILENO);
+
+        if (fd >= 3)
+                close_nointr_nofail(fd);
+
+        if (r < 0 || s < 0 || t < 0)
+                return -errno;
+
+        return 0;
+}
+
+bool is_clean_exit(int code, int status) {
+
+        if (code == CLD_EXITED)
+                return status == 0;
+
+        /* If a daemon does not implement handlers for some of the
+         * signals that's not considered an unclean shutdown */
+        if (code == CLD_KILLED)
+                return
+                        status == SIGHUP ||
+                        status == SIGINT ||
+                        status == SIGTERM ||
+                        status == SIGPIPE;
+
+        return false;
+}
+
+bool is_device_path(const char *path) {
+
+        /* Returns true on paths that refer to a device, either in
+         * sysfs or in /dev */
+
+        return
+                path_startswith(path, "/dev/") ||
+                path_startswith(path, "/sys/");
+}
+
 static const char *const ioprio_class_table[] = {
         [IOPRIO_CLASS_NONE] = "none",
         [IOPRIO_CLASS_RT] = "realtime",