Browse Source

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.
master
Zbigniew Jędrzejewski-Szmek 3 months ago
parent
commit
19ec21ba52
4 changed files with 18 additions and 26 deletions
  1. +3
    -7
      src/basic/conf-files.c
  2. +1
    -1
      src/basic/conf-files.h
  3. +1
    -1
      src/core/mount-setup.c
  4. +13
    -17
      src/test/test-conf-files.c

+ 3
- 7
src/basic/conf-files.c View File

@@ -115,7 +115,7 @@ static int files_add(

key = p;
} else {
p = strjoin(dirpath, "/", de->d_name);
p = path_join(dirpath, de->d_name);
if (!p)
return -ENOMEM;

@@ -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;


+ 1
- 1
src/basic/conf-files.h View File

@@ -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);

+ 1
- 1
src/core/mount-setup.c View File

@@ -437,7 +437,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");


+ 13
- 17
src/test/test-conf-files.c View File

@@ -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…
Cancel
Save