chiark / gitweb /
net-util: don't use libudev
[elogind.git] / src / shared / path-util.c
index 45099eeda8d6dc3898467bd31a5b8a087bcdb901..fcacf541ed83970be11fc44b842ae380bcb1ed88 100644 (file)
@@ -473,3 +473,34 @@ int find_binary(const char *name, char **filename) {
                 return -ENOENT;
         }
 }
+
+bool paths_check_timestamp(char **paths, usec_t *timestamp, bool update)
+{
+        unsigned int i;
+        bool changed = false;
+
+        assert(timestamp);
+
+        if (paths == NULL)
+                goto out;
+
+        for (i = 0; paths[i]; i++) {
+                struct stat stats;
+
+                if (stat(paths[i], &stats) < 0)
+                        continue;
+
+                /* first check */
+                if (*timestamp >= timespec_load(&stats.st_mtim))
+                        continue;
+
+                log_debug("timestamp of '%s' changed\n", paths[i]);
+                changed = true;
+
+                /* update timestamp */
+                if (update)
+                        *timestamp = timespec_load(&stats.st_mtim);
+        }
+out:
+        return changed;
+}