chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
build-sys: Angstrom support
[elogind.git]
/
src
/
util.c
diff --git
a/src/util.c
b/src/util.c
index 6037455f705fd3e6f0dd40eb8f9091dc7fb8bf55..f0051ee28581f1aaa040cce6be46e1e7037c3ee9 100644
(file)
--- a/
src/util.c
+++ b/
src/util.c
@@
-4011,7
+4011,7
@@
int detect_vm(const char **id) {
: "0" (eax)
);
: "0" (eax)
);
- hypervisor = !!(ecx &
ecx &
0x80000000U);
+ hypervisor = !!(ecx & 0x80000000U);
if (hypervisor) {
if (hypervisor) {
@@
-4576,17
+4576,25
@@
static int files_add(Hashmap *h, const char *path, const char *suffix) {
}
for (de = readdir(dir); de; de = readdir(dir)) {
}
for (de = readdir(dir); de; de = readdir(dir)) {
- char *f;
+ char *
p, *
f;
const char *base;
if (!file_is_conf(de, suffix))
continue;
const char *base;
if (!file_is_conf(de, suffix))
continue;
- if (asprintf(&
f
, "%s/%s", path, de->d_name) < 0) {
+ if (asprintf(&
p
, "%s/%s", path, de->d_name) < 0) {
r = -ENOMEM;
goto finish;
}
r = -ENOMEM;
goto finish;
}
+ f = canonicalize_file_name(p);
+ if (!f) {
+ log_error("Failed to canonicalize file name '%s': %m", p);
+ free(p);
+ continue;
+ }
+ free(p);
+
log_debug("found: %s\n", f);
base = f + strlen(path) + 1;
if (hashmap_put(h, base, f) <= 0)
log_debug("found: %s\n", f);
base = f + strlen(path) + 1;
if (hashmap_put(h, base, f) <= 0)
@@
-4606,39
+4614,55
@@
static int base_cmp(const void *a, const void *b) {
return strcmp(file_name_from_path(s1), file_name_from_path(s2));
}
return strcmp(file_name_from_path(s1), file_name_from_path(s2));
}
-char **conf_files_list(const char *suffix, const char *dir, ...) {
- Hashmap *fh;
+int conf_files_list(char ***strv, const char *suffix, const char *dir, ...) {
+ Hashmap *fh = NULL;
+ char **dirs = NULL;
char **files = NULL;
char **files = NULL;
+ char **p;
va_list ap;
va_list ap;
- int e = 0;
+ int r = 0;
+
+ va_start(ap, dir);
+ dirs = strv_new_ap(dir, ap);
+ va_end(ap);
+ if (!dirs) {
+ r = -ENOMEM;
+ goto finish;
+ }
+ if (!strv_path_canonicalize(dirs)) {
+ r = -ENOMEM;
+ goto finish;
+ }
+ if (!strv_uniq(dirs)) {
+ r = -ENOMEM;
+ goto finish;
+ }
fh = hashmap_new(string_hash_func, string_compare_func);
if (!fh) {
fh = hashmap_new(string_hash_func, string_compare_func);
if (!fh) {
-
e =
ENOMEM;
+
r = -
ENOMEM;
goto finish;
}
goto finish;
}
- va_start(ap, dir);
- while (dir) {
- if (files_add(fh, dir, suffix) < 0) {
+ STRV_FOREACH(p, dirs) {
+ if (files_add(fh, *p, suffix) < 0) {
log_error("Failed to search for files.");
log_error("Failed to search for files.");
-
e =
EINVAL;
+
r = -
EINVAL;
goto finish;
}
goto finish;
}
- dir = va_arg(ap, const char *);
}
}
- va_end(ap);
files = hashmap_get_strv(fh);
if (files == NULL) {
log_error("Failed to compose list of files.");
files = hashmap_get_strv(fh);
if (files == NULL) {
log_error("Failed to compose list of files.");
-
e =
ENOMEM;
+
r = -
ENOMEM;
goto finish;
}
qsort(files, hashmap_size(fh), sizeof(char *), base_cmp);
finish:
goto finish;
}
qsort(files, hashmap_size(fh), sizeof(char *), base_cmp);
finish:
+ strv_free(dirs);
hashmap_free(fh);
hashmap_free(fh);
-
errno = e
;
- return
files
;
+
*strv = files
;
+ return
r
;
}
}