chiark / gitweb /
shared/util: refactor fstab_node_to_udev_node
[elogind.git] / src / shared / util.c
index e615195af580711d4c919ad4461325612c6e9f80..d94bc695c8294dce8fef4ab4bb69c190255c6959 100644 (file)
@@ -1800,7 +1800,7 @@ char *ascii_strlower(char *t) {
         return t;
 }
 
-bool ignore_file(const char *filename) {
+static bool ignore_file_allow_backup(const char *filename) {
         assert(filename);
 
         return
@@ -1808,7 +1808,6 @@ bool ignore_file(const char *filename) {
                 streq(filename, "lost+found") ||
                 streq(filename, "aquota.user") ||
                 streq(filename, "aquota.group") ||
-                endswith(filename, "~") ||
                 endswith(filename, ".rpmnew") ||
                 endswith(filename, ".rpmsave") ||
                 endswith(filename, ".rpmorig") ||
@@ -1817,6 +1816,15 @@ bool ignore_file(const char *filename) {
                 endswith(filename, ".swp");
 }
 
+bool ignore_file(const char *filename) {
+        assert(filename);
+
+        if (endswith(filename, "~"))
+                return false;
+
+        return ignore_file_allow_backup(filename);
+}
+
 int fd_nonblock(int fd, bool nonblock) {
         int flags;
 
@@ -3089,7 +3097,6 @@ bool hostname_is_set(void) {
         return !isempty(u.nodename) && !streq(u.nodename, "(none)");
 }
 
-
 static char *lookup_uid(uid_t uid) {
         long bufsize;
         char *buf, *name;
@@ -4119,52 +4126,38 @@ void dual_timestamp_deserialize(const char *value, dual_timestamp *t) {
         }
 }
 
-char *fstab_node_to_udev_node(const char *p) {
+static char *tag_to_udev_node(const char *tagvalue, const char *by) {
         char *dn, *t, *u;
         int r;
 
         /* FIXME: to follow udev's logic 100% we need to leave valid
          * UTF8 chars unescaped */
 
-        if (startswith(p, "LABEL=")) {
-
-                if (!(u = unquote(p+6, "\"\'")))
-                        return NULL;
-
-                t = xescape(u, "/ ");
-                free(u);
-
-                if (!t)
-                        return NULL;
-
-                r = asprintf(&dn, "/dev/disk/by-label/%s", t);
-                free(t);
-
-                if (r < 0)
-                        return NULL;
-
-                return dn;
-        }
+        u = unquote(tagvalue, "\"\'");
+        if (u == NULL)
+                return NULL;
 
-        if (startswith(p, "UUID=")) {
+        t = xescape(u, "/ ");
+        free(u);
 
-                if (!(u = unquote(p+5, "\"\'")))
-                        return NULL;
+        if (t == NULL)
+                return NULL;
 
-                t = xescape(u, "/ ");
-                free(u);
+        r = asprintf(&dn, "/dev/disk/by-%s/%s", by, t);
+        free(t);
 
-                if (!t)
-                        return NULL;
+        if (r < 0)
+                return NULL;
 
-                r = asprintf(&dn, "/dev/disk/by-uuid/%s", t);
-                free(t);
+        return dn;
+}
 
-                if (r < 0)
-                        return NULL;
+char *fstab_node_to_udev_node(const char *p) {
+        if (startswith(p, "LABEL="))
+                return tag_to_udev_node(p+6, "label");
 
-                return dn;
-        }
+        if (startswith(p, "UUID="))
+                return tag_to_udev_node(p+5, "uuid");
 
         return strdup(p);
 }
@@ -4263,7 +4256,12 @@ bool dirent_is_file(const struct dirent *de) {
 bool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix) {
         assert(de);
 
-        if (!dirent_is_file(de))
+        if (de->d_type != DT_REG &&
+            de->d_type != DT_LNK &&
+            de->d_type != DT_UNKNOWN)
+                return false;
+
+        if (ignore_file_allow_backup(de->d_name))
                 return false;
 
         return endswith(de->d_name, suffix);
@@ -4357,7 +4355,7 @@ void execute_directory(const char *directory, DIR *d, char *argv[]) {
                 }
 
                 if ((path = hashmap_remove(pids, UINT_TO_PTR(si.si_pid)))) {
-                        if (!is_clean_exit(si.si_code, si.si_status)) {
+                        if (!is_clean_exit(si.si_code, si.si_status, NULL)) {
                                 if (si.si_code == CLD_EXITED)
                                         log_error("%s exited with exit status %i.", path, si.si_status);
                                 else