File: | build-scan/../src/basic/conf-files.c |
Warning: | line 106, column 41 The left operand of '&' is a garbage value |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* SPDX-License-Identifier: LGPL-2.1+ */ | |||
2 | ||||
3 | #include <dirent.h> | |||
4 | #include <errno(*__errno_location ()).h> | |||
5 | #include <stdarg.h> | |||
6 | #include <stdio.h> | |||
7 | #include <stdlib.h> | |||
8 | #include <string.h> | |||
9 | ||||
10 | #include "conf-files.h" | |||
11 | #include "def.h" | |||
12 | #include "dirent-util.h" | |||
13 | #include "fd-util.h" | |||
14 | #include "hashmap.h" | |||
15 | #include "log.h" | |||
16 | #include "macro.h" | |||
17 | #include "missing.h" | |||
18 | #include "path-util.h" | |||
19 | #include "set.h" | |||
20 | #include "stat-util.h" | |||
21 | #include "string-util.h" | |||
22 | #include "strv.h" | |||
23 | #include "terminal-util.h" | |||
24 | #include "util.h" | |||
25 | ||||
26 | static int files_add( | |||
27 | Hashmap *h, | |||
28 | Set *masked, | |||
29 | const char *suffix, | |||
30 | const char *root, | |||
31 | unsigned flags, | |||
32 | const char *path) { | |||
33 | ||||
34 | _cleanup_closedir___attribute__((cleanup(closedirp))) DIR *dir = NULL((void*)0); | |||
35 | const char *dirpath; | |||
36 | struct dirent *de; | |||
37 | int r; | |||
38 | ||||
39 | assert(h)do { if ((__builtin_expect(!!(!(h)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("h"), "../src/basic/conf-files.c", 39, __PRETTY_FUNCTION__ ); } while (0); | |||
| ||||
40 | assert((flags & CONF_FILES_FILTER_MASKED) == 0 || masked)do { if ((__builtin_expect(!!(!((flags & CONF_FILES_FILTER_MASKED ) == 0 || masked)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("(flags & CONF_FILES_FILTER_MASKED) == 0 || masked"), "../src/basic/conf-files.c" , 40, __PRETTY_FUNCTION__); } while (0); | |||
41 | assert(path)do { if ((__builtin_expect(!!(!(path)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("path"), "../src/basic/conf-files.c", 41 , __PRETTY_FUNCTION__); } while (0); | |||
42 | ||||
43 | dirpath = prefix_roota(root, path)({ const char* _path = (path), *_root = (root), *_ret; char * _p, *_n; size_t _l; while (_path[0] == '/' && _path[1 ] == '/') _path ++; if (empty_or_root(_root)) _ret = _path; else { _l = strlen(_root) + 1 + strlen(_path) + 1; _n = __builtin_alloca (_l); _p = stpcpy(_n, _root); while (_p > _n && _p [-1] == '/') _p--; if (_path[0] != '/') *(_p++) = '/'; strcpy (_p, _path); _ret = _n; } _ret; }); | |||
44 | ||||
45 | dir = opendir(dirpath); | |||
46 | if (!dir) { | |||
47 | if (errno(*__errno_location ()) == ENOENT2) | |||
48 | return 0; | |||
49 | ||||
50 | return log_debug_errno(errno, "Failed to open directory '%s': %m", dirpath)({ int _level = ((7)), _e = (((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/basic/conf-files.c", 50, __func__ , "Failed to open directory '%s': %m", dirpath) : -abs(_e); } ); | |||
51 | } | |||
52 | ||||
53 | FOREACH_DIRENT(de, dir, return -errno)for ((*__errno_location ()) = 0, de = readdir(dir);; (*__errno_location ()) = 0, de = readdir(dir)) if (!de) { if ((*__errno_location ()) > 0) { return -(*__errno_location ()); } break; } else if (hidden_or_backup_file((de)->d_name)) continue; else { | |||
54 | struct stat st; | |||
55 | char *p, *key; | |||
56 | ||||
57 | /* Does this match the suffix? */ | |||
58 | if (suffix && !endswith(de->d_name, suffix)) | |||
59 | continue; | |||
60 | ||||
61 | /* Has this file already been found in an earlier directory? */ | |||
62 | if (hashmap_contains(h, de->d_name)) { | |||
63 | log_debug("Skipping overridden file '%s/%s'.", dirpath, de->d_name)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/basic/conf-files.c", 63, __func__, "Skipping overridden file '%s/%s'." , dirpath, de->d_name) : -abs(_e); }); | |||
64 | continue; | |||
65 | } | |||
66 | ||||
67 | /* Has this been masked in an earlier directory? */ | |||
68 | if ((flags & CONF_FILES_FILTER_MASKED) && set_contains(masked, de->d_name)) { | |||
69 | log_debug("File '%s/%s' is masked by previous entry.", dirpath, de->d_name)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/basic/conf-files.c", 69, __func__, "File '%s/%s' is masked by previous entry." , dirpath, de->d_name) : -abs(_e); }); | |||
70 | continue; | |||
71 | } | |||
72 | ||||
73 | /* Read file metadata if we shall validate the check for file masks, for node types or whether the node is marked executable. */ | |||
74 | if (flags & (CONF_FILES_FILTER_MASKED|CONF_FILES_REGULAR|CONF_FILES_DIRECTORY|CONF_FILES_EXECUTABLE)) | |||
75 | if (fstatat(dirfd(dir), de->d_name, &st, 0) < 0) { | |||
76 | log_debug_errno(errno, "Failed to stat '%s/%s', ignoring: %m", dirpath, de->d_name)({ int _level = ((7)), _e = (((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((_realm) << 10 | (_level)), _e, "../src/basic/conf-files.c", 76, __func__ , "Failed to stat '%s/%s', ignoring: %m", dirpath, de->d_name ) : -abs(_e); }); | |||
77 | continue; | |||
78 | } | |||
79 | ||||
80 | /* Is this a masking entry? */ | |||
81 | if ((flags & CONF_FILES_FILTER_MASKED)) | |||
82 | if (null_or_empty(&st)) { | |||
83 | /* Mark this one as masked */ | |||
84 | r = set_put_strdup(masked, de->d_name); | |||
85 | if (r < 0) | |||
86 | return r; | |||
87 | ||||
88 | log_debug("File '%s/%s' is a mask.", dirpath, de->d_name)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/basic/conf-files.c", 88, __func__, "File '%s/%s' is a mask." , dirpath, de->d_name) : -abs(_e); }); | |||
89 | continue; | |||
90 | } | |||
91 | ||||
92 | /* Does this node have the right type? */ | |||
93 | if (flags & (CONF_FILES_REGULAR|CONF_FILES_DIRECTORY)) | |||
94 | if (!((flags & CONF_FILES_DIRECTORY) && S_ISDIR(st.st_mode)((((st.st_mode)) & 0170000) == (0040000))) && | |||
95 | !((flags & CONF_FILES_REGULAR) && S_ISREG(st.st_mode)((((st.st_mode)) & 0170000) == (0100000)))) { | |||
96 | log_debug("Ignoring '%s/%s', as it is not a of the right type.", dirpath, de->d_name)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/basic/conf-files.c", 96, __func__, "Ignoring '%s/%s', as it is not a of the right type." , dirpath, de->d_name) : -abs(_e); }); | |||
97 | continue; | |||
98 | } | |||
99 | ||||
100 | /* Does this node have the executable bit set? */ | |||
101 | if (flags & CONF_FILES_EXECUTABLE) | |||
102 | /* As requested: check if the file is marked exectuable. Note that we don't check access(X_OK) | |||
103 | * here, as we care about whether the file is marked executable at all, and not whether it is | |||
104 | * executable for us, because if so, such errors are stuff we should log about. */ | |||
105 | ||||
106 | if ((st.st_mode & 0111) == 0) { /* not executable */ | |||
| ||||
107 | log_debug("Ignoring '%s/%s', as it is not marked executable.", dirpath, de->d_name)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/basic/conf-files.c", 107, __func__, "Ignoring '%s/%s', as it is not marked executable." , dirpath, de->d_name) : -abs(_e); }); | |||
108 | continue; | |||
109 | } | |||
110 | ||||
111 | if (flags & CONF_FILES_BASENAME) { | |||
112 | p = strdup(de->d_name); | |||
113 | if (!p) | |||
114 | return -ENOMEM12; | |||
115 | ||||
116 | key = p; | |||
117 | } else { | |||
118 | p = strjoin(dirpath, "/", de->d_name)strjoin_real((dirpath), "/", de->d_name, ((void*)0)); | |||
119 | if (!p) | |||
120 | return -ENOMEM12; | |||
121 | ||||
122 | key = basename(p); | |||
123 | } | |||
124 | ||||
125 | r = hashmap_put(h, key, p); | |||
126 | if (r < 0) { | |||
127 | free(p); | |||
128 | return log_debug_errno(r, "Failed to add item to hashmap: %m")({ int _level = ((7)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/basic/conf-files.c", 128, __func__, "Failed to add item to hashmap: %m" ) : -abs(_e); }); | |||
129 | } | |||
130 | ||||
131 | assert(r > 0)do { if ((__builtin_expect(!!(!(r > 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("r > 0"), "../src/basic/conf-files.c" , 131, __PRETTY_FUNCTION__); } while (0); | |||
132 | } | |||
133 | ||||
134 | return 0; | |||
135 | } | |||
136 | ||||
137 | static int base_cmp(const void *a, const void *b) { | |||
138 | const char *s1, *s2; | |||
139 | ||||
140 | s1 = *(char * const *)a; | |||
141 | s2 = *(char * const *)b; | |||
142 | return strcmp(basename(s1), basename(s2)); | |||
143 | } | |||
144 | ||||
145 | static int conf_files_list_strv_internal(char ***strv, const char *suffix, const char *root, unsigned flags, char **dirs) { | |||
146 | _cleanup_hashmap_free___attribute__((cleanup(hashmap_freep))) Hashmap *fh = NULL((void*)0); | |||
147 | _cleanup_set_free_free___attribute__((cleanup(set_free_freep))) Set *masked = NULL((void*)0); | |||
148 | char **files, **p; | |||
149 | int r; | |||
150 | ||||
151 | assert(strv)do { if ((__builtin_expect(!!(!(strv)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("strv"), "../src/basic/conf-files.c", 151 , __PRETTY_FUNCTION__); } while (0); | |||
152 | ||||
153 | /* This alters the dirs string array */ | |||
154 | if (!path_strv_resolve_uniq(dirs, root)) | |||
155 | return -ENOMEM12; | |||
156 | ||||
157 | fh = hashmap_new(&path_hash_ops)internal_hashmap_new(&path_hash_ops ); | |||
158 | if (!fh) | |||
159 | return -ENOMEM12; | |||
160 | ||||
161 | if (flags & CONF_FILES_FILTER_MASKED) { | |||
162 | masked = set_new(&path_hash_ops)internal_set_new(&path_hash_ops ); | |||
163 | if (!masked) | |||
164 | return -ENOMEM12; | |||
165 | } | |||
166 | ||||
167 | STRV_FOREACH(p, dirs)for ((p) = (dirs); (p) && *(p); (p)++) { | |||
168 | r = files_add(fh, masked, suffix, root, flags, *p); | |||
169 | if (r == -ENOMEM12) | |||
170 | return r; | |||
171 | if (r < 0) | |||
172 | log_debug_errno(r, "Failed to search for files in %s, ignoring: %m", *p)({ int _level = ((7)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/basic/conf-files.c", 172, __func__, "Failed to search for files in %s, ignoring: %m" , *p) : -abs(_e); }); | |||
173 | } | |||
174 | ||||
175 | files = hashmap_get_strv(fh); | |||
176 | if (!files) | |||
177 | return -ENOMEM12; | |||
178 | ||||
179 | qsort_safe(files, hashmap_size(fh), sizeof(char *), base_cmp); | |||
180 | *strv = files; | |||
181 | ||||
182 | return 0; | |||
183 | } | |||
184 | ||||
185 | int conf_files_insert(char ***strv, const char *root, char **dirs, const char *path) { | |||
186 | /* Insert a path into strv, at the place honouring the usual sorting rules: | |||
187 | * - we first compare by the basename | |||
188 | * - and then we compare by dirname, allowing just one file with the given | |||
189 | * basename. | |||
190 | * This means that we will | |||
191 | * - add a new entry if basename(path) was not on the list, | |||
192 | * - do nothing if an entry with higher priority was already present, | |||
193 | * - do nothing if our new entry matches the existing entry, | |||
194 | * - replace the existing entry if our new entry has higher priority. | |||
195 | */ | |||
196 | size_t i; | |||
197 | char *t; | |||
198 | int r; | |||
199 | ||||
200 | for (i = 0; i < strv_length(*strv); i++) { | |||
201 | int c; | |||
202 | ||||
203 | c = base_cmp(*strv + i, &path); | |||
204 | if (c == 0) { | |||
205 | char **dir; | |||
206 | ||||
207 | /* Oh, there already is an entry with a matching name (the last component). */ | |||
208 | ||||
209 | STRV_FOREACH(dir, dirs)for ((dir) = (dirs); (dir) && *(dir); (dir)++) { | |||
210 | _cleanup_free___attribute__((cleanup(freep))) char *rdir = NULL((void*)0); | |||
211 | char *p1, *p2; | |||
212 | ||||
213 | rdir = prefix_root(root, *dir); | |||
214 | if (!rdir) | |||
215 | return -ENOMEM12; | |||
216 | ||||
217 | p1 = path_startswith((*strv)[i], rdir); | |||
218 | if (p1) | |||
219 | /* Existing entry with higher priority | |||
220 | * or same priority, no need to do anything. */ | |||
221 | return 0; | |||
222 | ||||
223 | p2 = path_startswith(path, *dir); | |||
224 | if (p2) { | |||
225 | /* Our new entry has higher priority */ | |||
226 | ||||
227 | t = prefix_root(root, path); | |||
228 | if (!t) | |||
229 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/basic/conf-files.c" , 229, __func__); | |||
230 | ||||
231 | return free_and_replace((*strv)[i], t)({ free((*strv)[i]); ((*strv)[i]) = (t); (t) = ((void*)0); 0; }); | |||
232 | } | |||
233 | } | |||
234 | ||||
235 | } else if (c > 0) | |||
236 | /* Following files have lower priority, let's go insert our | |||
237 | * new entry. */ | |||
238 | break; | |||
239 | ||||
240 | /* … we are not there yet, let's continue */ | |||
241 | } | |||
242 | ||||
243 | /* The new file has lower priority than all the existing entries */ | |||
244 | t = prefix_root(root, path); | |||
245 | if (!t) | |||
246 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/basic/conf-files.c" , 246, __func__); | |||
247 | ||||
248 | r = strv_insert(strv, i, t); | |||
249 | if (r < 0) | |||
250 | free(t); | |||
251 | return r; | |||
252 | } | |||
253 | ||||
254 | int conf_files_insert_nulstr(char ***strv, const char *root, const char *dirs, const char *path) { | |||
255 | _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **d = NULL((void*)0); | |||
256 | ||||
257 | assert(strv)do { if ((__builtin_expect(!!(!(strv)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("strv"), "../src/basic/conf-files.c", 257 , __PRETTY_FUNCTION__); } while (0); | |||
258 | ||||
259 | d = strv_split_nulstr(dirs); | |||
260 | if (!d) | |||
261 | return -ENOMEM12; | |||
262 | ||||
263 | return conf_files_insert(strv, root, d, path); | |||
264 | } | |||
265 | ||||
266 | int conf_files_list_strv(char ***strv, const char *suffix, const char *root, unsigned flags, const char* const* dirs) { | |||
267 | _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **copy = NULL((void*)0); | |||
268 | ||||
269 | assert(strv)do { if ((__builtin_expect(!!(!(strv)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("strv"), "../src/basic/conf-files.c", 269 , __PRETTY_FUNCTION__); } while (0); | |||
270 | ||||
271 | copy = strv_copy((char**) dirs); | |||
272 | if (!copy) | |||
273 | return -ENOMEM12; | |||
274 | ||||
275 | return conf_files_list_strv_internal(strv, suffix, root, flags, copy); | |||
276 | } | |||
277 | ||||
278 | int conf_files_list(char ***strv, const char *suffix, const char *root, unsigned flags, const char *dir, ...) { | |||
279 | _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **dirs = NULL((void*)0); | |||
280 | va_list ap; | |||
281 | ||||
282 | assert(strv)do { if ((__builtin_expect(!!(!(strv)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("strv"), "../src/basic/conf-files.c", 282 , __PRETTY_FUNCTION__); } while (0); | |||
283 | ||||
284 | va_start(ap, dir)__builtin_va_start(ap, dir); | |||
285 | dirs = strv_new_ap(dir, ap); | |||
286 | va_end(ap)__builtin_va_end(ap); | |||
287 | ||||
288 | if (!dirs) | |||
289 | return -ENOMEM12; | |||
290 | ||||
291 | return conf_files_list_strv_internal(strv, suffix, root, flags, dirs); | |||
292 | } | |||
293 | ||||
294 | int conf_files_list_nulstr(char ***strv, const char *suffix, const char *root, unsigned flags, const char *dirs) { | |||
295 | _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **d = NULL((void*)0); | |||
296 | ||||
297 | assert(strv)do { if ((__builtin_expect(!!(!(strv)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("strv"), "../src/basic/conf-files.c", 297 , __PRETTY_FUNCTION__); } while (0); | |||
298 | ||||
299 | d = strv_split_nulstr(dirs); | |||
300 | if (!d) | |||
301 | return -ENOMEM12; | |||
302 | ||||
303 | return conf_files_list_strv_internal(strv, suffix, root, flags, d); | |||
304 | } | |||
305 | ||||
306 | int conf_files_list_with_replacement( | |||
307 | const char *root, | |||
308 | char **config_dirs, | |||
309 | const char *replacement, | |||
310 | char ***files, | |||
311 | char **replace_file) { | |||
312 | ||||
313 | _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **f = NULL((void*)0); | |||
314 | _cleanup_free___attribute__((cleanup(freep))) char *p = NULL((void*)0); | |||
315 | int r; | |||
316 | ||||
317 | assert(config_dirs)do { if ((__builtin_expect(!!(!(config_dirs)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("config_dirs"), "../src/basic/conf-files.c" , 317, __PRETTY_FUNCTION__); } while (0); | |||
318 | assert(files)do { if ((__builtin_expect(!!(!(files)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("files"), "../src/basic/conf-files.c", 318 , __PRETTY_FUNCTION__); } while (0); | |||
319 | assert(replace_file || !replacement)do { if ((__builtin_expect(!!(!(replace_file || !replacement) ),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("replace_file || !replacement" ), "../src/basic/conf-files.c", 319, __PRETTY_FUNCTION__); } while (0); | |||
320 | ||||
321 | r = conf_files_list_strv(&f, ".conf", root, 0, (const char* const*) config_dirs); | |||
322 | if (r < 0) | |||
323 | return log_error_errno(r, "Failed to enumerate config files: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/basic/conf-files.c", 323, __func__, "Failed to enumerate config files: %m" ) : -abs(_e); }); | |||
324 | ||||
325 | if (replacement) { | |||
326 | r = conf_files_insert(&f, root, config_dirs, replacement); | |||
327 | if (r < 0) | |||
328 | return log_error_errno(r, "Failed to extend config file list: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/basic/conf-files.c", 328, __func__, "Failed to extend config file list: %m" ) : -abs(_e); }); | |||
329 | ||||
330 | p = prefix_root(root, replacement); | |||
331 | if (!p) | |||
332 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/basic/conf-files.c" , 332, __func__); | |||
333 | } | |||
334 | ||||
335 | *files = TAKE_PTR(f)({ typeof(f) _ptr_ = (f); (f) = ((void*)0); _ptr_; }); | |||
336 | if (replace_file) | |||
337 | *replace_file = TAKE_PTR(p)({ typeof(p) _ptr_ = (p); (p) = ((void*)0); _ptr_; }); | |||
338 | return 0; | |||
339 | } | |||
340 | ||||
341 | int conf_files_cat(const char *root, const char *name) { | |||
342 | _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **dirs = NULL((void*)0), **files = NULL((void*)0); | |||
343 | _cleanup_free___attribute__((cleanup(freep))) char *path = NULL((void*)0); | |||
344 | const char *dir; | |||
345 | char **t; | |||
346 | int r; | |||
347 | ||||
348 | NULSTR_FOREACH(dir, CONF_PATHS_NULSTR(""))for ((dir) = ("/etc/" "" "\0" "/run/" "" "\0" "/usr/local/lib/" "" "\0" "/usr/lib/" "" "\0"); (dir) && *(dir); (dir) = strchr((dir), 0)+1) { | |||
349 | assert(endswith(dir, "/"))do { if ((__builtin_expect(!!(!(endswith(dir, "/"))),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("endswith(dir, \"/\")"), "../src/basic/conf-files.c" , 349, __PRETTY_FUNCTION__); } while (0); | |||
350 | r = strv_extendf(&dirs, "%s%s.d", dir, name); | |||
351 | if (r < 0) | |||
352 | return log_error_errno(r, "Failed to build directory list: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/basic/conf-files.c", 352, __func__, "Failed to build directory list: %m" ) : -abs(_e); }); | |||
353 | } | |||
354 | ||||
355 | r = conf_files_list_strv(&files, ".conf", root, 0, (const char* const*) dirs); | |||
356 | if (r < 0) | |||
357 | return log_error_errno(r, "Failed to query file list: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/basic/conf-files.c", 357, __func__, "Failed to query file list: %m" ) : -abs(_e); }); | |||
358 | ||||
359 | path = path_join(root, "/etc", name); | |||
360 | if (!path) | |||
361 | return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/basic/conf-files.c" , 361, __func__); | |||
362 | ||||
363 | if (DEBUG_LOGGING(__builtin_expect(!!(log_get_max_level_realm(LOG_REALM_SYSTEMD ) >= 7),0))) { | |||
364 | log_debug("Looking for configuration in:")({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/basic/conf-files.c", 364, __func__, "Looking for configuration in:" ) : -abs(_e); }); | |||
365 | log_debug(" %s", path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/basic/conf-files.c", 365, __func__, " %s", path) : -abs(_e); }); | |||
366 | STRV_FOREACH(t, dirs)for ((t) = (dirs); (t) && *(t); (t)++) | |||
367 | log_debug(" %s/*.conf", *t)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/basic/conf-files.c", 367, __func__, " %s/*.conf", *t) : -abs(_e); }); | |||
368 | } | |||
369 | ||||
370 | /* show */ | |||
371 | return cat_files(path, files, CAT_FLAGS_MAIN_FILE_OPTIONAL); | |||
372 | } |