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:
48c5876
)
basic: modernize conf-files.c a bit
author
Lennart Poettering
<lennart@poettering.net>
Sat, 2 Jan 2016 20:32:45 +0000
(21:32 +0100)
committer
Sven Eden
<yamakuzure@gmx.net>
Wed, 17 May 2017 13:22:15 +0000
(15:22 +0200)
src/basic/conf-files.c
patch
|
blob
|
history
diff --git
a/src/basic/conf-files.c
b/src/basic/conf-files.c
index 75dad228e394574bdfc0964a132371adb7267fd9..5854caeb518d1a2ec49b07520c73a0ebd757688d 100644
(file)
--- a/
src/basic/conf-files.c
+++ b/
src/basic/conf-files.c
@@
-41,6
+41,7
@@
static int files_add(Hashmap *h, const char *root, const char *path, const char *suffix) {
_cleanup_closedir_ DIR *dir = NULL;
const char *dirpath;
static int files_add(Hashmap *h, const char *root, const char *path, const char *suffix) {
_cleanup_closedir_ DIR *dir = NULL;
const char *dirpath;
+ struct dirent *de;
int r;
assert(path);
int r;
assert(path);
@@
-55,18
+56,9
@@
static int files_add(Hashmap *h, const char *root, const char *path, const char
return -errno;
}
return -errno;
}
- for (;;) {
- struct dirent *de;
+ FOREACH_DIRENT(de, dir, return -errno) {
char *p;
char *p;
- errno = 0;
- de = readdir(dir);
- if (!de && errno != 0)
- return -errno;
-
- if (!de)
- break;
-
if (!dirent_is_file_with_suffix(de, suffix))
continue;
if (!dirent_is_file_with_suffix(de, suffix))
continue;
@@
-116,17
+108,15
@@
static int conf_files_list_strv_internal(char ***strv, const char *suffix, const
STRV_FOREACH(p, dirs) {
r = files_add(fh, root, *p, suffix);
STRV_FOREACH(p, dirs) {
r = files_add(fh, root, *p, suffix);
- if (r == -ENOMEM)
{
+ if (r == -ENOMEM)
return r;
return r;
- } else if (r < 0)
- log_debug_errno(r, "Failed to search for files in %s: %m",
- *p);
+ if (r < 0)
+ log_debug_errno(r, "Failed to search for files in %s, ignoring: %m", *p);
}
files = hashmap_get_strv(fh);
}
files = hashmap_get_strv(fh);
- if (
files == NULL) {
+ if (
!files)
return -ENOMEM;
return -ENOMEM;
- }
qsort_safe(files, hashmap_size(fh), sizeof(char *), base_cmp);
*strv = files;
qsort_safe(files, hashmap_size(fh), sizeof(char *), base_cmp);
*strv = files;