diff options
author | Lucas De Marchi <lucas.demarchi@profusion.mobi> | 2011-12-12 15:00:51 -0200 |
---|---|---|
committer | Lucas De Marchi <lucas.demarchi@profusion.mobi> | 2011-12-12 15:00:51 -0200 |
commit | 4782396cc464feb84a1552379e1909a9446178cc (patch) | |
tree | 677920a36f569d6a7bc43c55ab6ea75dd4c0851d | |
parent | 016d619cd982d1f25e2756a52767eaad3bde5064 (diff) | |
download | kmod-4782396cc464feb84a1552379e1909a9446178cc.tar.gz kmod-4782396cc464feb84a1552379e1909a9446178cc.tar.bz2 kmod-4782396cc464feb84a1552379e1909a9446178cc.zip |
Do not stat() dir twice
-rw-r--r-- | libkmod/libkmod-config.c | 27 |
1 files changed, 7 insertions, 20 deletions
diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c index bdb290b..605e021 100644 --- a/libkmod/libkmod-config.c +++ b/libkmod/libkmod-config.c @@ -382,21 +382,16 @@ static bool conf_files_filter_out(struct kmod_ctx *ctx, const char *path, return 0; } +/* + * Iterate over a directory (given by @path) and save the list of + * configuration files in @list. + */ static DIR *conf_files_list(struct kmod_ctx *ctx, struct kmod_list **list, const char *path) { - struct stat st; DIR *d; int err; - if (stat(path, &st) < 0) - return NULL; - - if (!S_ISDIR(st.st_mode)) { - *list = kmod_list_append(*list, path); - return NULL; - } - d = opendir(path); if (d == NULL) { err = errno; @@ -404,6 +399,8 @@ static DIR *conf_files_list(struct kmod_ctx *ctx, struct kmod_list **list, return NULL; } + *list = NULL; + for (;;) { struct dirent ent, *entp; struct kmod_list *l, *tmp; @@ -470,7 +467,7 @@ int kmod_config_new(struct kmod_ctx *ctx, struct kmod_config **p_config, for (i = 0; config_paths[i] != NULL; i++) { const char *path = config_paths[i]; - struct kmod_list *list = NULL; + struct kmod_list *list; struct stat st; DIR *d; @@ -494,16 +491,6 @@ int kmod_config_new(struct kmod_ctx *ctx, struct kmod_config **p_config, d = conf_files_list(ctx, &list, path); - if (d == NULL) { - ERR(ctx, "returned list but no directory?\n"); - while (list) { - free(list->data); - kmod_list_remove(list); - } - continue; - } - - /* treat all the entries in that dir */ for (; list != NULL; list = kmod_list_remove(list)) { int fd = openat(dirfd(d), list->data, O_RDONLY); DBG(ctx, "parsing file '%s/%s': %d\n", path, |