chiark / gitweb /
path_check_timestamp: only keep the most recent timestamp
authorTom Gundersen <teg@jklm.no>
Tue, 29 Oct 2013 14:15:53 +0000 (15:15 +0100)
committerTom Gundersen <teg@jklm.no>
Tue, 29 Oct 2013 15:12:11 +0000 (16:12 +0100)
There is no point in keeping one timestamp for each directory, as we only
ever care about the most recent one.

src/shared/path-util.c
src/udev/net/link-config.c
src/udev/udev-rules.c

index def7a7409a30ed85ef8ebf573b5df489977f81b8..fcacf541ed83970be11fc44b842ae380bcb1ed88 100644 (file)
@@ -474,11 +474,13 @@ int find_binary(const char *name, char **filename) {
         }
 }
 
-bool paths_check_timestamp(char **paths, usec_t *paths_ts_usec, bool update)
+bool paths_check_timestamp(char **paths, usec_t *timestamp, bool update)
 {
         unsigned int i;
         bool changed = false;
 
+        assert(timestamp);
+
         if (paths == NULL)
                 goto out;
 
@@ -488,18 +490,16 @@ bool paths_check_timestamp(char **paths, usec_t *paths_ts_usec, bool update)
                 if (stat(paths[i], &stats) < 0)
                         continue;
 
-                if (paths_ts_usec[i] == timespec_load(&stats.st_mtim))
+                /* first check */
+                if (*timestamp >= 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;
-                }
+                log_debug("timestamp of '%s' changed\n", paths[i]);
+                changed = true;
 
                 /* update timestamp */
                 if (update)
-                        paths_ts_usec[i] = timespec_load(&stats.st_mtim);
+                        *timestamp = timespec_load(&stats.st_mtim);
         }
 out:
         return changed;
index 0b5916be4c96ab2f45be480a36c39944937b4784..598f93e384cdfaa40627fc62ad279f7047c3ed0f 100644 (file)
@@ -46,7 +46,7 @@ struct link_config_ctx {
         sd_rtnl *rtnl;
 
         char **link_dirs;
-        usec_t *link_dirs_ts_usec;
+        usec_t link_dirs_ts_usec;
 };
 
 int link_config_ctx_new(link_config_ctx **ret) {
@@ -89,12 +89,6 @@ int link_config_ctx_new(link_config_ctx **ret) {
                 return -ENOMEM;
         }
 
-        ctx->link_dirs_ts_usec = calloc(strv_length(ctx->link_dirs), sizeof(usec_t));
-        if(!ctx->link_dirs_ts_usec) {
-                link_config_ctx_free(ctx);
-                return -ENOMEM;
-        }
-
         *ret = ctx;
         return 0;
 }
@@ -126,7 +120,6 @@ void link_config_ctx_free(link_config_ctx *ctx) {
         sd_rtnl_unref(ctx->rtnl);
 
         strv_free(ctx->link_dirs);
-        free(ctx->link_dirs_ts_usec);
         link_configs_free(ctx);
 
         free(ctx);
@@ -183,8 +176,8 @@ int link_config_load(link_config_ctx *ctx) {
 
         link_configs_free(ctx);
 
-        /* update timestamps */
-        paths_check_timestamp(ctx->link_dirs, ctx->link_dirs_ts_usec, true);
+        /* update timestamp */
+        paths_check_timestamp(ctx->link_dirs, &ctx->link_dirs_ts_usec, true);
 
         r = conf_files_list_strv(&files, ".link", NULL, (const char **)ctx->link_dirs);
         if (r < 0) {
@@ -202,7 +195,7 @@ int link_config_load(link_config_ctx *ctx) {
 }
 
 bool link_config_should_reload(link_config_ctx *ctx) {
-        return paths_check_timestamp(ctx->link_dirs, ctx->link_dirs_ts_usec, false);
+        return paths_check_timestamp(ctx->link_dirs, &ctx->link_dirs_ts_usec, false);
 }
 
 static bool match_config(link_config *match, struct udev_device *device) {
index 58da79b876def0e546a2c26b3adb55659f577231..4437d80529e81d85b3ed056261cae1ed278634cf 100644 (file)
@@ -49,7 +49,7 @@ struct uid_gid {
 struct udev_rules {
         struct udev *udev;
         char **dirs;
-        usec_t *dirs_ts_usec;
+        usec_t dirs_ts_usec;
         int resolve_names;
 
         /* every key in the rules file becomes a token */
@@ -1653,9 +1653,6 @@ struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names)
         }
         strv_uniq(rules->dirs);
 
-        rules->dirs_ts_usec = calloc(strv_length(rules->dirs), sizeof(usec_t));
-        if(!rules->dirs_ts_usec)
-                return udev_rules_unref(rules);
         udev_rules_check_timestamp(rules);
 
         r = conf_files_list_strv(&files, ".rules", NULL, (const char **)rules->dirs);
@@ -1711,14 +1708,13 @@ struct udev_rules *udev_rules_unref(struct udev_rules *rules)
         free(rules->uids);
         free(rules->gids);
         strv_free(rules->dirs);
-        free(rules->dirs_ts_usec);
         free(rules);
         return NULL;
 }
 
 bool udev_rules_check_timestamp(struct udev_rules *rules)
 {
-        return paths_check_timestamp(rules->dirs, rules->dirs_ts_usec, true);
+        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)