mirror of
https://github.com/systemd/systemd
synced 2024-09-15 22:30:22 +00:00
basic/conf-files: make conf_files_list() take just a single directory
This function had two users (apart from tests), and both only used one argument. And it seems likely that if we need to pass more directories, either the _nulstr() or the _strv() form would be used. Let's simplify the code.
This commit is contained in:
parent
48da02ec6f
commit
36b12282e1
|
@ -261,16 +261,12 @@ int conf_files_list_strv(char ***strv, const char *suffix, const char *root, uns
|
|||
return conf_files_list_strv_internal(strv, suffix, root, flags, copy);
|
||||
}
|
||||
|
||||
int conf_files_list(char ***strv, const char *suffix, const char *root, unsigned flags, const char *dir, ...) {
|
||||
int conf_files_list(char ***strv, const char *suffix, const char *root, unsigned flags, const char *dir) {
|
||||
_cleanup_strv_free_ char **dirs = NULL;
|
||||
va_list ap;
|
||||
|
||||
assert(strv);
|
||||
|
||||
va_start(ap, dir);
|
||||
dirs = strv_new_ap(dir, ap);
|
||||
va_end(ap);
|
||||
|
||||
dirs = strv_new(dir);
|
||||
if (!dirs)
|
||||
return -ENOMEM;
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ enum {
|
|||
CONF_FILES_FILTER_MASKED = 1 << 4,
|
||||
};
|
||||
|
||||
int conf_files_list(char ***ret, const char *suffix, const char *root, unsigned flags, const char *dir, ...) _sentinel_;
|
||||
int conf_files_list(char ***ret, const char *suffix, const char *root, unsigned flags, const char *dir);
|
||||
int conf_files_list_strv(char ***ret, const char *suffix, const char *root, unsigned flags, const char* const* dirs);
|
||||
int conf_files_list_nulstr(char ***ret, const char *suffix, const char *root, unsigned flags, const char *dirs);
|
||||
int conf_files_insert(char ***strv, const char *root, char **dirs, const char *path);
|
||||
|
|
|
@ -422,7 +422,7 @@ static int relabel_extra(void) {
|
|||
|
||||
r = conf_files_list(&files, ".relabel", NULL,
|
||||
CONF_FILES_FILTER_MASKED | CONF_FILES_REGULAR,
|
||||
"/run/systemd/relabel-extra.d/", NULL);
|
||||
"/run/systemd/relabel-extra.d/");
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to enumerate /run/systemd/relabel-extra.d/, ignoring: %m");
|
||||
|
||||
|
|
|
@ -257,7 +257,7 @@ static int boot_entries_find(
|
|||
assert(entries);
|
||||
assert(n_entries);
|
||||
|
||||
r = conf_files_list(&files, ".conf", NULL, 0, dir, NULL);
|
||||
r = conf_files_list(&files, ".conf", NULL, 0, dir);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to list files in \"%s\": %m", dir);
|
||||
|
||||
|
|
|
@ -42,38 +42,34 @@ static void setup_test_dir(char *tmp_dir, const char *files, ...) {
|
|||
static void test_conf_files_list(bool use_root) {
|
||||
char tmp_dir[] = "/tmp/test-conf-files-XXXXXX";
|
||||
_cleanup_strv_free_ char **found_files = NULL, **found_files2 = NULL;
|
||||
const char *root_dir, *search_1, *search_2, *expect_a, *expect_b, *expect_c, *mask;
|
||||
const char *root_dir, *search, *expect_a, *expect_b, *expect_c, *mask;
|
||||
|
||||
log_debug("/* %s(%s) */", __func__, yes_no(use_root));
|
||||
log_info("/* %s(%s) */", __func__, yes_no(use_root));
|
||||
|
||||
setup_test_dir(tmp_dir,
|
||||
"/dir1/a.conf",
|
||||
"/dir2/a.conf",
|
||||
"/dir2/b.conf",
|
||||
"/dir2/c.foo",
|
||||
"/dir2/d.conf",
|
||||
"/dir/a.conf",
|
||||
"/dir/b.conf",
|
||||
"/dir/c.foo",
|
||||
NULL);
|
||||
|
||||
mask = strjoina(tmp_dir, "/dir1/d.conf");
|
||||
mask = strjoina(tmp_dir, "/dir/d.conf");
|
||||
assert_se(symlink("/dev/null", mask) >= 0);
|
||||
|
||||
if (use_root) {
|
||||
root_dir = tmp_dir;
|
||||
search_1 = "/dir1";
|
||||
search_2 = "/dir2";
|
||||
search = "/dir";
|
||||
} else {
|
||||
root_dir = NULL;
|
||||
search_1 = strjoina(tmp_dir, "/dir1");
|
||||
search_2 = strjoina(tmp_dir, "/dir2");
|
||||
search = strjoina(tmp_dir, "/dir");
|
||||
}
|
||||
|
||||
expect_a = strjoina(tmp_dir, "/dir1/a.conf");
|
||||
expect_b = strjoina(tmp_dir, "/dir2/b.conf");
|
||||
expect_c = strjoina(tmp_dir, "/dir2/c.foo");
|
||||
expect_a = strjoina(tmp_dir, "/dir/a.conf");
|
||||
expect_b = strjoina(tmp_dir, "/dir/b.conf");
|
||||
expect_c = strjoina(tmp_dir, "/dir/c.foo");
|
||||
|
||||
log_debug("/* Check when filtered by suffix */");
|
||||
|
||||
assert_se(conf_files_list(&found_files, ".conf", root_dir, CONF_FILES_FILTER_MASKED, search_1, search_2, NULL) == 0);
|
||||
assert_se(conf_files_list(&found_files, ".conf", root_dir, CONF_FILES_FILTER_MASKED, search) == 0);
|
||||
strv_print(found_files);
|
||||
|
||||
assert_se(found_files);
|
||||
|
@ -82,7 +78,7 @@ static void test_conf_files_list(bool use_root) {
|
|||
assert_se(!found_files[2]);
|
||||
|
||||
log_debug("/* Check when unfiltered */");
|
||||
assert_se(conf_files_list(&found_files2, NULL, root_dir, CONF_FILES_FILTER_MASKED, search_1, search_2, NULL) == 0);
|
||||
assert_se(conf_files_list(&found_files2, NULL, root_dir, CONF_FILES_FILTER_MASKED, search) == 0);
|
||||
strv_print(found_files2);
|
||||
|
||||
assert_se(found_files2);
|
||||
|
|
Loading…
Reference in a new issue