udev: move udev_rules_check_timestamp to shared
authorTom Gundersen <teg@jklm.no>
Fri, 25 Oct 2013 22:36:49 +0000 (00:36 +0200)
committerTom Gundersen <teg@jklm.no>
Sat, 26 Oct 2013 12:34:31 +0000 (14:34 +0200)
I want to use this from a bulitin in a subsequent patch.

src/shared/path-util.c
src/shared/path-util.h
src/udev/udev-rules.c

index 45099eeda8d6dc3898467bd31a5b8a087bcdb901..def7a7409a30ed85ef8ebf573b5df489977f81b8 100644 (file)
@@ -473,3 +473,34 @@ int find_binary(const char *name, char **filename) {
                 return -ENOENT;
         }
 }
+
+bool paths_check_timestamp(char **paths, usec_t *paths_ts_usec, bool update)
+{
+        unsigned int i;
+        bool changed = false;
+
+        if (paths == NULL)
+                goto out;
+
+        for (i = 0; paths[i]; i++) {
+                struct stat stats;
+
+                if (stat(paths[i], &stats) < 0)
+                        continue;
+
+                if (paths_ts_usec[i] == timespec_load(&stats.st_mtim))
+                        continue;
+
+                /* first check */
+                if (paths_ts_usec[i] != 0) {
+                        log_debug("reload - timestamp of '%s' changed\n", paths[i]);
+                        changed = true;
+                }
+
+                /* update timestamp */
+                if (update)
+                        paths_ts_usec[i] = timespec_load(&stats.st_mtim);
+        }
+out:
+        return changed;
+}
index 0a42de7e27093f0041c24b78a6009dbfbf5e3241..42b4189d77d65c7d5ac0988e16aaacbb446cb64d 100644 (file)
@@ -24,6 +24,7 @@
 #include <stdbool.h>
 
 #include "macro.h"
+#include "time-util.h"
 
 #ifdef HAVE_SPLIT_USR
 #  define DEFAULT_PATH "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
@@ -52,6 +53,8 @@ int path_is_os_tree(const char *path);
 
 int find_binary(const char *name, char **filename);
 
+bool paths_check_timestamp(char **paths, usec_t *paths_ts_usec, bool update);
+
 /* Iterates through the path prefixes of the specified path, going up
  * the tree, to root. Also returns "" (and not "/"!) for the root
  * directory. Excludes the specified directory itself */
index 9d9529a0fe38c316ba9d9eccd8ca0fba1a09ee79..58da79b876def0e546a2c26b3adb55659f577231 100644 (file)
@@ -1718,32 +1718,7 @@ struct udev_rules *udev_rules_unref(struct udev_rules *rules)
 
 bool udev_rules_check_timestamp(struct udev_rules *rules)
 {
-        unsigned int i;
-        bool changed = false;
-
-        if (rules == NULL)
-                goto out;
-
-        for (i = 0; rules->dirs[i]; i++) {
-                struct stat stats;
-
-                if (stat(rules->dirs[i], &stats) < 0)
-                        continue;
-
-                if (rules->dirs_ts_usec[i] == timespec_load(&stats.st_mtim))
-                        continue;
-
-                /* first check */
-                if (rules->dirs_ts_usec[i] != 0) {
-                        log_debug("reload - timestamp of '%s' changed\n", rules->dirs[i]);
-                        changed = true;
-                }
-
-                /* update timestamp */
-                rules->dirs_ts_usec[i] = timespec_load(&stats.st_mtim);
-        }
-out:
-        return changed;
+        return paths_check_timestamp(rules->dirs, rules->dirs_ts_usec, true);
 }
 
 static int match_key(struct udev_rules *rules, struct token *token, const char *val)