From: Lucas De Marchi Date: Sat, 31 Dec 2011 20:48:05 +0000 (-0200) Subject: config: save list of config paths with their timestamps X-Git-Tag: v3~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b6a4dfb1b4c02a1094e022bc3553250949f73ca9;p=thirdparty%2Fkmod.git config: save list of config paths with their timestamps Save a list of config paths with their timestamps so they can be checked later. --- diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c index fdffa806..db9fbd6d 100644 --- a/libkmod/libkmod-config.c +++ b/libkmod/libkmod-config.c @@ -607,6 +607,10 @@ void kmod_config_free(struct kmod_config *config) while (config->softdeps) kmod_config_free_softdep(config, config->softdeps); + for (; config->paths != NULL; + config->paths = kmod_list_remove(config->paths)) + free(config->paths->data); + free(config); } @@ -699,7 +703,8 @@ static int conf_files_insert_sorted(struct kmod_ctx *ctx, * Insert configuration files in @list, ignoring duplicates */ static int conf_files_list(struct kmod_ctx *ctx, struct kmod_list **list, - const char *path) + const char *path, + unsigned long long *path_stamp) { DIR *d; int err; @@ -711,6 +716,8 @@ static int conf_files_list(struct kmod_ctx *ctx, struct kmod_list **list, return err; } + *path_stamp = ts_usec(&st.st_mtim); + if (S_ISREG(st.st_mode)) { conf_files_insert_sorted(ctx, list, path, NULL); return 0; @@ -757,20 +764,39 @@ int kmod_config_new(struct kmod_ctx *ctx, struct kmod_config **p_config, { struct kmod_config *config; struct kmod_list *list = NULL; + struct kmod_list *path_list = NULL; size_t i; - *p_config = config = calloc(1, sizeof(struct kmod_config)); - if (config == NULL) - return -ENOMEM; - - config->ctx = ctx; - for (i = 0; config_paths[i] != NULL; i++) { const char *path = config_paths[i]; + unsigned long long path_stamp = 0; + size_t pathlen; + struct kmod_list *tmp; + struct kmod_config_path *cf; + + if (conf_files_list(ctx, &list, path, &path_stamp) < 0) + continue; + + pathlen = strlen(path) + 1; + cf = malloc(sizeof(*cf) + pathlen); + if (cf == NULL) + goto oom; - conf_files_list(ctx, &list, path); + cf->stamp = path_stamp; + memcpy(cf->path, path, pathlen); + + tmp = kmod_list_append(path_list, cf); + if (tmp == NULL) + goto oom; + path_list = tmp; } + *p_config = config = calloc(1, sizeof(struct kmod_config)); + if (config == NULL) + goto oom; + + config->paths = path_list; + for (; list != NULL; list = kmod_list_remove(list)) { char fn[PATH_MAX]; struct conf_file *cf = list->data; @@ -794,4 +820,13 @@ int kmod_config_new(struct kmod_ctx *ctx, struct kmod_config **p_config, kmod_config_parse_kcmdline(config); return 0; + +oom: + for (; list != NULL; list = kmod_list_remove(list)) + free(list->data); + + for (; path_list != NULL; path_list = kmod_list_remove(path_list)) + free(path_list->data); + + return -ENOMEM; } diff --git a/libkmod/libkmod-private.h b/libkmod/libkmod-private.h index 3c750f1c..71f8c206 100644 --- a/libkmod/libkmod-private.h +++ b/libkmod/libkmod-private.h @@ -97,6 +97,11 @@ const struct kmod_list *kmod_get_softdeps(const struct kmod_ctx *ctx) __must_che /* libkmod-config.c */ +struct kmod_config_path { + unsigned long long stamp; + char path[]; +}; + struct kmod_config { struct kmod_ctx *ctx; struct kmod_list *aliases; @@ -105,7 +110,10 @@ struct kmod_config { struct kmod_list *remove_commands; struct kmod_list *install_commands; struct kmod_list *softdeps; + + struct kmod_list *paths; }; + int kmod_config_new(struct kmod_ctx *ctx, struct kmod_config **config, const char * const *config_paths) __attribute__((nonnull(1, 2,3))); void kmod_config_free(struct kmod_config *config) __attribute__((nonnull(1))); const char *kmod_blacklist_get_modname(const struct kmod_list *l) __attribute__((nonnull(1)));