]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
config: save list of config paths with their timestamps
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Sat, 31 Dec 2011 20:48:05 +0000 (18:48 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Sun, 1 Jan 2012 08:18:01 +0000 (06:18 -0200)
Save a list of config paths with their timestamps so they can be checked
later.

libkmod/libkmod-config.c
libkmod/libkmod-private.h

index fdffa8060b2425eac29ad740cea1babb44357f8f..db9fbd6db19ac213267adb5fdbd1be777c5ce6ac 100644 (file)
@@ -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;
 }
index 3c750f1ca7d1b94f4b0983e5362ecf287239d30f..71f8c2066893b2e5bcbe5f84649f73b4c075dc48 100644 (file)
@@ -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)));