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);
}
* 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;
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;
{
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;
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;
}
/* libkmod-config.c */
+struct kmod_config_path {
+ unsigned long long stamp;
+ char path[];
+};
+
struct kmod_config {
struct kmod_ctx *ctx;
struct kmod_list *aliases;
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)));