chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
7850b3b
)
shared: conf-files - use root parameter and convert to auto-cleanup
author
Kay Sievers
<kay@vrfy.org>
Fri, 8 Feb 2013 09:45:30 +0000
(10:45 +0100)
committer
Kay Sievers
<kay@vrfy.org>
Fri, 8 Feb 2013 10:52:10 +0000
(11:52 +0100)
src/shared/conf-files.c
patch
|
blob
|
history
diff --git
a/src/shared/conf-files.c
b/src/shared/conf-files.c
index 368b7bf6bb3b319d60b88ed24ba92962f01c4377..5bbd2388d3d03084663b118becac7d7d77094958 100644
(file)
--- a/
src/shared/conf-files.c
+++ b/
src/shared/conf-files.c
@@
-38,10
+38,13
@@
#include "conf-files.h"
static int files_add(Hashmap *h, const char *root, const char *path, const char *suffix) {
#include "conf-files.h"
static int files_add(Hashmap *h, const char *root, const char *path, const char *suffix) {
- DIR *dir;
-
int r = 0
;
+
_cleanup_closedir_
DIR *dir;
+
_cleanup_free_ char *dirpath = NULL
;
- dir = opendir(path);
+ if (asprintf(&dirpath, "%s%s", root ? root : "", path) < 0)
+ return -ENOMEM;
+
+ dir = opendir(dirpath);
if (!dir) {
if (errno == ENOENT)
return 0;
if (!dir) {
if (errno == ENOENT)
return 0;
@@
-51,14
+54,12
@@
static int files_add(Hashmap *h, const char *root, const char *path, const char
for (;;) {
struct dirent *de;
union dirent_storage buf;
for (;;) {
struct dirent *de;
union dirent_storage buf;
- int k;
char *p;
char *p;
+ int err;
- k = readdir_r(dir, &buf.de, &de);
- if (k != 0) {
- r = -k;
- goto finish;
- }
+ err = readdir_r(dir, &buf.de, &de);
+ if (err != 0)
+ return err;
if (!de)
break;
if (!de)
break;
@@
-66,10
+67,8
@@
static int files_add(Hashmap *h, const char *root, const char *path, const char
if (!dirent_is_file_with_suffix(de, suffix))
continue;
if (!dirent_is_file_with_suffix(de, suffix))
continue;
- if (asprintf(&p, "%s/%s", path, de->d_name) < 0) {
- r = -ENOMEM;
- goto finish;
- }
+ if (asprintf(&p, "%s/%s", dirpath, de->d_name) < 0)
+ return -ENOMEM;
if (hashmap_put(h, path_get_file_name(p), p) <= 0) {
log_debug("Skip overridden file: %s.", p);
if (hashmap_put(h, path_get_file_name(p), p) <= 0) {
log_debug("Skip overridden file: %s.", p);
@@
-77,9
+76,7
@@
static int files_add(Hashmap *h, const char *root, const char *path, const char
}
}
}
}
-finish:
- closedir(dir);
- return r;
+ return 0;
}
static int base_cmp(const void *a, const void *b) {
}
static int base_cmp(const void *a, const void *b) {