mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-12 09:17:44 +03:00
shared: conf-files - use root parameter and convert to auto-cleanup
This commit is contained in:
parent
7850b3b837
commit
e02caf30ac
@ -38,10 +38,13 @@
|
|||||||
#include "conf-files.h"
|
#include "conf-files.h"
|
||||||
|
|
||||||
static int files_add(Hashmap *h, const char *root, const char *path, const char *suffix) {
|
static int files_add(Hashmap *h, const char *root, const char *path, const char *suffix) {
|
||||||
DIR *dir;
|
_cleanup_closedir_ DIR *dir;
|
||||||
int r = 0;
|
_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 (!dir) {
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT)
|
||||||
return 0;
|
return 0;
|
||||||
@ -51,14 +54,12 @@ static int files_add(Hashmap *h, const char *root, const char *path, const char
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
struct dirent *de;
|
struct dirent *de;
|
||||||
union dirent_storage buf;
|
union dirent_storage buf;
|
||||||
int k;
|
|
||||||
char *p;
|
char *p;
|
||||||
|
int err;
|
||||||
|
|
||||||
k = readdir_r(dir, &buf.de, &de);
|
err = readdir_r(dir, &buf.de, &de);
|
||||||
if (k != 0) {
|
if (err != 0)
|
||||||
r = -k;
|
return err;
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!de)
|
if (!de)
|
||||||
break;
|
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))
|
if (!dirent_is_file_with_suffix(de, suffix))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (asprintf(&p, "%s/%s", path, de->d_name) < 0) {
|
if (asprintf(&p, "%s/%s", dirpath, de->d_name) < 0)
|
||||||
r = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hashmap_put(h, path_get_file_name(p), p) <= 0) {
|
if (hashmap_put(h, path_get_file_name(p), p) <= 0) {
|
||||||
log_debug("Skip overridden file: %s.", p);
|
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:
|
return 0;
|
||||||
closedir(dir);
|
|
||||||
return r;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int base_cmp(const void *a, const void *b) {
|
static int base_cmp(const void *a, const void *b) {
|
||||||
|
Loading…
Reference in New Issue
Block a user