From 30016f21b36599a0c5c563f165db48ddb32d6521 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 30 Nov 2018 10:40:38 +0100 Subject: [PATCH] tree-wide: replace path_join with path_join_many --- src/analyze/analyze-verify.c | 5 +---- src/basic/conf-files.c | 6 +++--- src/basic/path-util.c | 2 +- src/basic/path-util.h | 5 ----- src/basic/selinux-util.c | 6 ++---- src/journal/journalctl.c | 2 +- src/libsystemd/sd-hwdb/hwdb-util.c | 2 +- src/resolve/test-dns-packet.c | 2 +- src/shared/install.c | 4 ++-- src/shared/pretty-print.c | 2 +- src/shared/tests.c | 2 +- src/systemctl/systemctl.c | 8 ++++---- src/test/test-execute.c | 2 +- src/test/test-journal-importer.c | 4 ++-- src/test/test-mountpoint-util.c | 20 ++++++++++---------- src/test/test-path-util.c | 2 +- src/test/test-path.c | 2 +- src/test/test-umount.c | 4 ++-- src/tmpfiles/tmpfiles.c | 2 +- src/udev/udev-event.c | 2 +- src/udev/udev-node.c | 4 ++-- src/udev/udevadm-trigger.c | 2 +- src/udev/udevadm-util.c | 2 +- 23 files changed, 41 insertions(+), 51 deletions(-) diff --git a/src/analyze/analyze-verify.c b/src/analyze/analyze-verify.c index 42f2a8f345..1abba6d3da 100644 --- a/src/analyze/analyze-verify.c +++ b/src/analyze/analyze-verify.c @@ -43,10 +43,7 @@ static int prepare_filename(const char *filename, char **ret) { if (!dir) return -ENOMEM; - if (with_instance) - c = path_join(NULL, dir, with_instance); - else - c = path_join(NULL, dir, name); + c = path_join_many(dir, with_instance ?: name); if (!c) return -ENOMEM; diff --git a/src/basic/conf-files.c b/src/basic/conf-files.c index 7b44ae277d..4211600611 100644 --- a/src/basic/conf-files.c +++ b/src/basic/conf-files.c @@ -216,7 +216,7 @@ int conf_files_insert(char ***strv, const char *root, char **dirs, const char *p p2 = path_startswith(path, *dir); if (p2) { /* Our new entry has higher priority */ - t = path_join(root, path, NULL); + t = path_join_many(strempty(root), path); if (!t) return log_oom(); @@ -232,7 +232,7 @@ int conf_files_insert(char ***strv, const char *root, char **dirs, const char *p /* … we are not there yet, let's continue */ } - t = path_join(root, path, NULL); + t = path_join_many(strempty(root), path); if (!t) return log_oom(); @@ -318,7 +318,7 @@ int conf_files_list_with_replacement( if (r < 0) return log_error_errno(r, "Failed to extend config file list: %m"); - p = path_join(root, replacement, NULL); + p = path_join_many(strempty(root), replacement); if (!p) return log_oom(); } diff --git a/src/basic/path-util.c b/src/basic/path-util.c index 7d1e0f3f2d..cb9987da4b 100644 --- a/src/basic/path-util.c +++ b/src/basic/path-util.c @@ -110,7 +110,7 @@ int path_make_absolute_cwd(const char *p, char **ret) { if (r < 0) return r; - c = path_join(NULL, cwd, p); + c = path_join_many(cwd, p); } if (!c) return -ENOMEM; diff --git a/src/basic/path-util.h b/src/basic/path-util.h index 8bda450ff3..e1e50bc2bd 100644 --- a/src/basic/path-util.h +++ b/src/basic/path-util.h @@ -51,11 +51,6 @@ bool path_equal(const char *a, const char *b) _pure_; bool path_equal_or_files_same(const char *a, const char *b, int flags); char* path_join_many_internal(const char *first, ...) _sentinel_; #define path_join_many(x, ...) path_join_many_internal(x, __VA_ARGS__, NULL) -static inline char* path_join(const char *root, const char *path, const char *rest) { - assert(path); - - return path_join_many(strempty(root), path, rest); -} char* path_simplify(char *path, bool kill_dots); diff --git a/src/basic/selinux-util.c b/src/basic/selinux-util.c index d5228f6746..213b6c421e 100644 --- a/src/basic/selinux-util.c +++ b/src/basic/selinux-util.c @@ -366,11 +366,9 @@ int mac_selinux_create_file_prepare_at(int dirfd, const char *path, mode_t mode) if (r < 0) return r; - abspath = path_join(NULL, p, path); - if (!abspath) + path = abspath = path_join_many(p, path); + if (!path) return -ENOMEM; - - path = abspath; } r = selinux_create_file_prepare_abspath(path, mode); diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 4fe6ae7367..19d1d3cfc7 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -2110,7 +2110,7 @@ int main(int argc, char *argv[]) { case ACTION_UPDATE_CATALOG: { _cleanup_free_ char *database; - database = path_join(arg_root, CATALOG_DATABASE, NULL); + database = path_join_many(strempty(arg_root), CATALOG_DATABASE); if (!database) { r = log_oom(); goto finish; diff --git a/src/libsystemd/sd-hwdb/hwdb-util.c b/src/libsystemd/sd-hwdb/hwdb-util.c index 87259daadc..5bd594e94e 100644 --- a/src/libsystemd/sd-hwdb/hwdb-util.c +++ b/src/libsystemd/sd-hwdb/hwdb-util.c @@ -651,7 +651,7 @@ int hwdb_update(const char *root, const char *hwdb_bin_dir, bool strict, bool co log_debug("strings dedup'ed: %8zu bytes (%8zu)", trie->strings->dedup_len, trie->strings->dedup_count); - hwdb_bin = path_join(root, hwdb_bin_dir ?: default_hwdb_bin_dir, "hwdb.bin"); + hwdb_bin = path_join_many(strempty(root), hwdb_bin_dir ?: default_hwdb_bin_dir, "hwdb.bin"); if (!hwdb_bin) return -ENOMEM; diff --git a/src/resolve/test-dns-packet.c b/src/resolve/test-dns-packet.c index 0dac05e7be..a6b0ae1b81 100644 --- a/src/resolve/test-dns-packet.c +++ b/src/resolve/test-dns-packet.c @@ -103,7 +103,7 @@ int main(int argc, char **argv) { N = argc - 1; fnames = argv + 1; } else { - pkts_glob = path_join(NULL, get_testdata_dir(), "test-resolve/*.pkts"); + pkts_glob = path_join_many(get_testdata_dir(), "test-resolve/*.pkts"); assert_se(glob(pkts_glob, GLOB_NOSORT, NULL, &g) == 0); N = g.gl_pathc; fnames = g.gl_pathv; diff --git a/src/shared/install.c b/src/shared/install.c index 28e07a23a5..2ba9db3bd4 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -1464,7 +1464,7 @@ static int unit_file_search( STRV_FOREACH(p, paths->search_path) { char *path; - path = path_join(NULL, *p, dropin_dir_name); + path = path_join_many(*p, dropin_dir_name); if (!path) return -ENOMEM; @@ -1478,7 +1478,7 @@ static int unit_file_search( STRV_FOREACH(p, paths->search_path) { char *path; - path = path_join(NULL, *p, dropin_template_dir_name); + path = path_join_many(*p, dropin_template_dir_name); if (!path) return -ENOMEM; diff --git a/src/shared/pretty-print.c b/src/shared/pretty-print.c index 1086018645..ac21c996a8 100644 --- a/src/shared/pretty-print.c +++ b/src/shared/pretty-print.c @@ -217,7 +217,7 @@ int conf_files_cat(const char *root, const char *name) { if (r < 0) return log_error_errno(r, "Failed to query file list: %m"); - path = path_join(root, "/etc", name); + path = path_join_many(strempty(root), "/etc", name); if (!path) return log_oom(); diff --git a/src/shared/tests.c b/src/shared/tests.c index bab39685ff..be584dc0fa 100644 --- a/src/shared/tests.c +++ b/src/shared/tests.c @@ -46,7 +46,7 @@ static void load_testdata_env(void) { assert_se(readlink_and_make_absolute("/proc/self/exe", &s) >= 0); dirname(s); - envpath = path_join(NULL, s, "systemd-runtest.env"); + envpath = path_join_many(s, "systemd-runtest.env"); if (load_env_file_pairs(NULL, envpath, &pairs) < 0) return; diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index effbd5c07c..1015c64227 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -2425,7 +2425,7 @@ static int unit_file_find_path(LookupPaths *lp, const char *unit_name, char **re _cleanup_free_ char *path = NULL, *lpath = NULL; int r; - path = path_join(NULL, *p, unit_name); + path = path_join_many(*p, unit_name); if (!path) return log_oom(); @@ -3516,9 +3516,9 @@ static int load_kexec_kernel(void) { return -EINVAL; } - kernel = path_join(NULL, where, e->kernel); + kernel = path_join_many(where, e->kernel); if (!strv_isempty(e->initrd)) - initrd = path_join(NULL, where, *e->initrd); + initrd = path_join_many(where, *e->initrd); options = strv_join(e->options, " "); if (!options) return log_oom(); @@ -5975,7 +5975,7 @@ static int enable_sysv_units(const char *verb, char **args) { if (found_native && streq(verb, "is-enabled")) continue; - p = path_join(arg_root, SYSTEM_SYSVINIT_PATH, name); + p = path_join_many(strempty(arg_root), SYSTEM_SYSVINIT_PATH, name); if (!p) return log_oom(); diff --git a/src/test/test-execute.c b/src/test/test-execute.c index a8e9d9c2a1..85f13cbe97 100644 --- a/src/test/test-execute.c +++ b/src/test/test-execute.c @@ -781,7 +781,7 @@ int main(int argc, char *argv[]) { return log_tests_skipped("cgroupfs not available"); assert_se(runtime_dir = setup_fake_runtime_dir()); - test_execute_path = path_join(NULL, get_testdata_dir(), "test-execute"); + test_execute_path = path_join_many(get_testdata_dir(), "test-execute"); assert_se(set_unit_path(test_execute_path) >= 0); /* Unset VAR1, VAR2 and VAR3 which are used in the PassEnvironment test diff --git a/src/test/test-journal-importer.c b/src/test/test-journal-importer.c index c1ceb0bbd8..e8db0bad64 100644 --- a/src/test/test-journal-importer.c +++ b/src/test/test-journal-importer.c @@ -25,7 +25,7 @@ static void test_basic_parsing(void) { _cleanup_free_ char *journal_data_path = NULL; int r; - journal_data_path = path_join(NULL, get_testdata_dir(), "journal-data/journal-1.txt"); + journal_data_path = path_join_many(get_testdata_dir(), "journal-data/journal-1.txt"); imp.fd = open(journal_data_path, O_RDONLY|O_CLOEXEC); assert_se(imp.fd >= 0); @@ -56,7 +56,7 @@ static void test_bad_input(void) { _cleanup_free_ char *journal_data_path = NULL; int r; - journal_data_path = path_join(NULL, get_testdata_dir(), "journal-data/journal-2.txt"); + journal_data_path = path_join_many(get_testdata_dir(), "journal-data/journal-2.txt"); imp.fd = open(journal_data_path, O_RDONLY|O_CLOEXEC); assert_se(imp.fd >= 0); diff --git a/src/test/test-mountpoint-util.c b/src/test/test-mountpoint-util.c index b8b37cf600..ccc38752bf 100644 --- a/src/test/test-mountpoint-util.c +++ b/src/test/test-mountpoint-util.c @@ -123,9 +123,9 @@ static void test_path_is_mount_point(void) { /* file mountpoints */ assert_se(mkdtemp(tmp_dir) != NULL); - file1 = path_join(NULL, tmp_dir, "file1"); + file1 = path_join_many(tmp_dir, "file1"); assert_se(file1); - file2 = path_join(NULL, tmp_dir, "file2"); + file2 = path_join_many(tmp_dir, "file2"); assert_se(file2); fd = open(file1, O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0664); assert_se(fd > 0); @@ -133,10 +133,10 @@ static void test_path_is_mount_point(void) { fd = open(file2, O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0664); assert_se(fd > 0); close(fd); - link1 = path_join(NULL, tmp_dir, "link1"); + link1 = path_join_many(tmp_dir, "link1"); assert_se(link1); assert_se(symlink("file1", link1) == 0); - link2 = path_join(NULL, tmp_dir, "link2"); + link2 = path_join_many(tmp_dir, "link2"); assert_se(link1); assert_se(symlink("file2", link2) == 0); @@ -146,16 +146,16 @@ static void test_path_is_mount_point(void) { assert_se(path_is_mount_point(link1, NULL, 0) == 0); /* directory mountpoints */ - dir1 = path_join(NULL, tmp_dir, "dir1"); + dir1 = path_join_many(tmp_dir, "dir1"); assert_se(dir1); assert_se(mkdir(dir1, 0755) == 0); - dirlink1 = path_join(NULL, tmp_dir, "dirlink1"); + dirlink1 = path_join_many(tmp_dir, "dirlink1"); assert_se(dirlink1); assert_se(symlink("dir1", dirlink1) == 0); - dirlink1file = path_join(NULL, tmp_dir, "dirlink1file"); + dirlink1file = path_join_many(tmp_dir, "dirlink1file"); assert_se(dirlink1file); assert_se(symlink("dirlink1/file", dirlink1file) == 0); - dir2 = path_join(NULL, tmp_dir, "dir2"); + dir2 = path_join_many(tmp_dir, "dir2"); assert_se(dir2); assert_se(mkdir(dir2, 0755) == 0); @@ -165,7 +165,7 @@ static void test_path_is_mount_point(void) { assert_se(path_is_mount_point(dirlink1, NULL, 0) == 0); /* file in subdirectory mountpoints */ - dir1file = path_join(NULL, dir1, "file"); + dir1file = path_join_many(dir1, "file"); assert_se(dir1file); fd = open(dir1file, O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0664); assert_se(fd > 0); @@ -206,7 +206,7 @@ static void test_path_is_mount_point(void) { assert_se(rlt == 1); /* dirs */ - dir2file = path_join(NULL, dir2, "file"); + dir2file = path_join_many(dir2, "file"); assert_se(dir2file); fd = open(dir2file, O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0664); assert_se(fd > 0); diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c index dcce591f39..cfe8cc0510 100644 --- a/src/test/test-path-util.c +++ b/src/test/test-path-util.c @@ -234,7 +234,7 @@ static void test_path_join(void) { #define test_join(root, path, rest, expected) { \ _cleanup_free_ char *z = NULL; \ - z = path_join(root, path, rest); \ + z = path_join_many(strempty(root), path, rest); \ assert_se(streq(z, expected)); \ } diff --git a/src/test/test-path.c b/src/test/test-path.c index edc0479522..6d8dab3c70 100644 --- a/src/test/test-path.c +++ b/src/test/test-path.c @@ -252,7 +252,7 @@ int main(int argc, char *argv[]) { test_setup_logging(LOG_INFO); - test_path = path_join(NULL, get_testdata_dir(), "test-path"); + test_path = path_join_many(get_testdata_dir(), "test-path"); assert_se(set_unit_path(test_path) >= 0); assert_se(runtime_dir = setup_fake_runtime_dir()); diff --git a/src/test/test-umount.c b/src/test/test-umount.c index 1b243d03ef..2b53c1bae8 100644 --- a/src/test/test-umount.c +++ b/src/test/test-umount.c @@ -16,7 +16,7 @@ static void test_mount_points_list(const char *fname) { log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/self/mountinfo"); if (fname) - fname = testdata_fname = path_join(NULL, get_testdata_dir(), fname); + fname = testdata_fname = path_join_many(get_testdata_dir(), fname); LIST_HEAD_INIT(mp_list_head); assert_se(mount_points_list_get(fname, &mp_list_head) >= 0); @@ -38,7 +38,7 @@ static void test_swap_list(const char *fname) { log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/swaps"); if (fname) - fname = testdata_fname = path_join(NULL, get_testdata_dir(), fname); + fname = testdata_fname = path_join_many(get_testdata_dir(), fname); LIST_HEAD_INIT(mp_list_head); assert_se(swap_list_get(fname, &mp_list_head) >= 0); diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 21ba6dd330..854ca2d33c 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -1844,7 +1844,7 @@ static int item_do(Item *i, int fd, const char *path, fdaction_t action) { else { _cleanup_free_ char *de_path = NULL; - de_path = path_join(NULL, path, de->d_name); + de_path = path_join_many(path, de->d_name); if (!de_path) q = log_oom(); else diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c index c60c02e7fe..b5252926cd 100644 --- a/src/udev/udev-event.c +++ b/src/udev/udev-event.c @@ -633,7 +633,7 @@ int udev_event_spawn(struct udev_event *event, if (!path_is_absolute(argv[0])) { char *program; - program = path_join(NULL, UDEVLIBEXECDIR, argv[0]); + program = path_join_many(UDEVLIBEXECDIR, argv[0]); if (!program) return log_oom(); diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c index 648a102265..a12dbcfc44 100644 --- a/src/udev/udev-node.c +++ b/src/udev/udev-node.c @@ -200,10 +200,10 @@ static int link_update(sd_device *dev, const char *slink, bool add) { return log_device_debug_errno(dev, r, "Failed to get id_filename: %m"); util_path_encode(slink + STRLEN("/dev"), name_enc, sizeof(name_enc)); - dirname = path_join(NULL, "/run/udev/links/", name_enc); + dirname = path_join_many("/run/udev/links/", name_enc); if (!dirname) return log_oom(); - filename = path_join(NULL, dirname, id_filename); + filename = path_join_many(dirname, id_filename); if (!filename) return log_oom(); diff --git a/src/udev/udevadm-trigger.c b/src/udev/udevadm-trigger.c index 38035b5c92..14fb241a29 100644 --- a/src/udev/udevadm-trigger.c +++ b/src/udev/udevadm-trigger.c @@ -35,7 +35,7 @@ static int exec_list(sd_device_enumerator *e, const char *action, Set *settle_se if (arg_dry_run) continue; - filename = path_join(NULL, syspath, "uevent"); + filename = path_join_many(syspath, "uevent"); if (!filename) return log_oom(); diff --git a/src/udev/udevadm-util.c b/src/udev/udevadm-util.c index 1dbcf979b1..22f43740c3 100644 --- a/src/udev/udevadm-util.c +++ b/src/udev/udevadm-util.c @@ -14,7 +14,7 @@ int find_device(const char *id, const char *prefix, sd_device **ret) { assert(ret); if (prefix && !path_startswith(id, prefix)) { - buf = path_join(NULL, prefix, id); + buf = path_join_many(prefix, id); if (!buf) return -ENOMEM; id = buf;