path_check_timestamp: only keep the most recent timestamp
There is no point in keeping one timestamp for each directory, as we only ever care about the most recent one.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user