diff options
author | Lennart Poettering <lennart@poettering.net> | 2019-06-22 20:02:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-22 20:02:46 +0200 |
commit | cee97d57687e93e07a8ee36edf0e0d0f3317fccc (patch) | |
tree | 7278ba990e750ae119cacfd6c19a0866579374ab | |
parent | bpf-firewall: optimization for IPAddressXYZ="any" (and unprivileged users) (diff) | |
parent | sd-path: use _cleanup_ attribute (diff) | |
download | systemd-cee97d57687e93e07a8ee36edf0e0d0f3317fccc.tar.xz systemd-cee97d57687e93e07a8ee36edf0e0d0f3317fccc.zip |
Merge pull request #12836 from yuwata/tree-wide-replace-strjoin
tree-wide: replace strjoin() with path_join()
44 files changed, 95 insertions, 126 deletions
diff --git a/src/basic/blockdev-util.c b/src/basic/blockdev-util.c index 0d7ea83b75..625bbdd943 100644 --- a/src/basic/blockdev-util.c +++ b/src/basic/blockdev-util.c @@ -115,11 +115,11 @@ int block_get_originating(dev_t dt, dev_t *ret) { * setups, however, only if both partitions are on the same physical device. Hence, let's * verify this. */ - u = strjoin(p, "/", de->d_name, "/../dev"); + u = path_join(p, de->d_name, "../dev"); if (!u) return -ENOMEM; - v = strjoin(p, "/", found->d_name, "/../dev"); + v = path_join(p, found->d_name, "../dev"); if (!v) return -ENOMEM; diff --git a/src/basic/btrfs-util.c b/src/basic/btrfs-util.c index db6c0c3f1e..10ca893da0 100644 --- a/src/basic/btrfs-util.c +++ b/src/basic/btrfs-util.c @@ -1530,7 +1530,7 @@ static int subvol_snapshot_children( if (old_child_fd < 0) return -errno; - np = strjoin(subvolume, "/", ino_args.name); + np = path_join(subvolume, ino_args.name); if (!np) return -ENOMEM; diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index 60ce9b7d3a..9b145aa70f 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -388,7 +388,7 @@ int cg_kill_recursive( while ((r = cg_read_subgroup(d, &fn)) > 0) { _cleanup_free_ char *p = NULL; - p = strjoin(path, "/", fn); + p = path_join(path, fn); free(fn); if (!p) return -ENOMEM; @@ -522,7 +522,7 @@ int cg_migrate_recursive( while ((r = cg_read_subgroup(d, &fn)) > 0) { _cleanup_free_ char *p = NULL; - p = strjoin(pfrom, "/", fn); + p = path_join(pfrom, fn); free(fn); if (!p) return -ENOMEM; @@ -610,13 +610,13 @@ static int join_path_legacy(const char *controller, const char *path, const char dn = controller_to_dirname(controller); if (isempty(path) && isempty(suffix)) - t = strappend("/sys/fs/cgroup/", dn); + t = path_join("/sys/fs/cgroup", dn); else if (isempty(path)) - t = strjoin("/sys/fs/cgroup/", dn, "/", suffix); + t = path_join("/sys/fs/cgroup", dn, suffix); else if (isempty(suffix)) - t = strjoin("/sys/fs/cgroup/", dn, "/", path); + t = path_join("/sys/fs/cgroup", dn, path); else - t = strjoin("/sys/fs/cgroup/", dn, "/", path, "/", suffix); + t = path_join("/sys/fs/cgroup", dn, path, suffix); if (!t) return -ENOMEM; @@ -632,11 +632,11 @@ static int join_path_unified(const char *path, const char *suffix, char **fs) { if (isempty(path) && isempty(suffix)) t = strdup("/sys/fs/cgroup"); else if (isempty(path)) - t = strappend("/sys/fs/cgroup/", suffix); + t = path_join("/sys/fs/cgroup", suffix); else if (isempty(suffix)) - t = strappend("/sys/fs/cgroup/", path); + t = path_join("/sys/fs/cgroup", path); else - t = strjoin("/sys/fs/cgroup/", path, "/", suffix); + t = path_join("/sys/fs/cgroup", path, suffix); if (!t) return -ENOMEM; @@ -663,7 +663,7 @@ int cg_get_path(const char *controller, const char *path, const char *suffix, ch else if (!path) t = strdup(suffix); else - t = strjoin(path, "/", suffix); + t = path_join(path, suffix); if (!t) return -ENOMEM; @@ -1267,7 +1267,7 @@ int cg_is_empty_recursive(const char *controller, const char *path) { while ((r = cg_read_subgroup(d, &fn)) > 0) { _cleanup_free_ char *p = NULL; - p = strjoin(path, "/", fn); + p = path_join(path, fn); free(fn); if (!p) return -ENOMEM; diff --git a/src/basic/conf-files.c b/src/basic/conf-files.c index a0d17e8a0e..3f36b5cc34 100644 --- a/src/basic/conf-files.c +++ b/src/basic/conf-files.c @@ -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; diff --git a/src/basic/copy.c b/src/basic/copy.c index eed9cfdff7..36ea7821f2 100644 --- a/src/basic/copy.c +++ b/src/basic/copy.c @@ -566,7 +566,7 @@ static int fd_copy_directory( if (progress_path) { if (display_path) - child_display_path = dp = strjoin(display_path, "/", de->d_name); + child_display_path = dp = path_join(display_path, de->d_name); else child_display_path = de->d_name; diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 4c18212668..40a20c2b3b 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -589,10 +589,7 @@ static int search_and_fopen_internal(const char *path, const char *mode, const c _cleanup_free_ char *p = NULL; FILE *f; - if (root) - p = strjoin(root, *i, "/", path); - else - p = strjoin(*i, "/", path); + p = path_join(root, *i, path); if (!p) return -ENOMEM; diff --git a/src/basic/path-util.c b/src/basic/path-util.c index 0ad1cce8a5..570f88627d 100644 --- a/src/basic/path-util.c +++ b/src/basic/path-util.c @@ -68,10 +68,7 @@ char *path_make_absolute(const char *p, const char *prefix) { if (path_is_absolute(p) || isempty(prefix)) return strdup(p); - if (endswith(prefix, "/")) - return strjoin(prefix, p); - else - return strjoin(prefix, "/", p); + return path_join(prefix, p); } int safe_getcwd(char **ret) { @@ -581,7 +578,7 @@ int find_binary(const char *name, char **ret) { if (!path_is_absolute(element)) continue; - j = strjoin(element, "/", name); + j = path_join(element, name); if (!j) return -ENOMEM; diff --git a/src/basic/tmpfile-util.c b/src/basic/tmpfile-util.c index 5100d6a5ff..afcf58aeac 100644 --- a/src/basic/tmpfile-util.c +++ b/src/basic/tmpfile-util.c @@ -320,7 +320,7 @@ int mkdtemp_malloc(const char *template, char **ret) { if (r < 0) return r; - p = strjoin(tmp, "/XXXXXX"); + p = path_join(tmp, "XXXXXX"); } if (!p) return -ENOMEM; diff --git a/src/busctl/busctl-introspect.c b/src/busctl/busctl-introspect.c index 18254efd2d..7016c90ddc 100644 --- a/src/busctl/busctl-introspect.c +++ b/src/busctl/busctl-introspect.c @@ -4,6 +4,7 @@ #include "alloc-util.h" #include "busctl-introspect.h" +#include "path-util.h" #include "string-util.h" #include "util.h" #include "xml.h" @@ -250,10 +251,7 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth node_path = TAKE_PTR(name); else { - if (endswith(prefix, "/")) - node_path = strappend(prefix, name); - else - node_path = strjoin(prefix, "/", name); + node_path = path_join(prefix, name); if (!node_path) return log_oom(); } diff --git a/src/cgls/cgls.c b/src/cgls/cgls.c index adc028bc8e..34d95c7660 100644 --- a/src/cgls/cgls.c +++ b/src/cgls/cgls.c @@ -243,7 +243,7 @@ static int run(int argc, char *argv[]) { controller = c ?: SYSTEMD_CGROUP_CONTROLLER; if (p) { - j = strjoin(root, "/", p); + j = path_join(root, p); if (!j) return log_oom(); diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index fff6b505cc..dca594a083 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -459,7 +459,7 @@ static int refresh_one( if (r == 0) break; - p = strjoin(path, "/", fn); + p = path_join(path, fn); if (!p) return -ENOMEM; diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 7f6a22155b..4b16bb3367 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -1617,11 +1617,7 @@ char *unit_default_cgroup_path(const Unit *u) { if (!escaped) return NULL; - if (slice) - return strjoin(u->manager->cgroup_root, "/", slice, "/", - escaped); - else - return strjoin(u->manager->cgroup_root, "/", escaped); + return path_join(empty_to_root(u->manager->cgroup_root), slice, escaped); } int unit_set_cgroup_path(Unit *u, const char *path) { @@ -2475,7 +2471,7 @@ static int unit_watch_pids_in_path(Unit *u, const char *path) { while ((r = cg_read_subgroup(d, &fn)) > 0) { _cleanup_free_ char *p = NULL; - p = strjoin(path, "/", fn); + p = path_join(path, fn); free(fn); if (!p) diff --git a/src/core/dbus-service.c b/src/core/dbus-service.c index bc7ffb81eb..a0699bee60 100644 --- a/src/core/dbus-service.c +++ b/src/core/dbus-service.c @@ -349,7 +349,7 @@ static int bus_service_set_transient_property( if (e) { char *z; - z = strjoin("/run/", e); + z = path_join("/run", e); if (!z) return log_oom(); diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c index a60362fff6..0dac290bc1 100644 --- a/src/core/dbus-unit.c +++ b/src/core/dbus-unit.c @@ -956,7 +956,7 @@ static int append_cgroup(sd_bus_message *reply, const char *p, Set *pids) { if (r == 0) break; - j = strjoin(p, "/", g); + j = path_join(p, g); if (!j) return -ENOMEM; diff --git a/src/core/execute.c b/src/core/execute.c index af994d97d1..921449391d 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -2334,7 +2334,7 @@ static int compile_bind_mounts( * directory. For that we overmount the usually inaccessible "private" subdirectory with a * tmpfs that makes it accessible and is empty except for the submounts we do this for. */ - private_root = strjoin(params->prefix[t], "/private"); + private_root = path_join(params->prefix[t], "private"); if (!private_root) { r = -ENOMEM; goto finish; @@ -2350,9 +2350,9 @@ static int compile_bind_mounts( if (context->dynamic_user && !IN_SET(t, EXEC_DIRECTORY_RUNTIME, EXEC_DIRECTORY_CONFIGURATION)) - s = strjoin(params->prefix[t], "/private/", *suffix); + s = path_join(params->prefix[t], "private", *suffix); else - s = strjoin(params->prefix[t], "/", *suffix); + s = path_join(params->prefix[t], *suffix); if (!s) { r = -ENOMEM; goto finish; @@ -2364,7 +2364,7 @@ static int compile_bind_mounts( /* When RootDirectory= or RootImage= are set, then the symbolic link to the private * directory is not created on the root directory. So, let's bind-mount the directory * on the 'non-private' place. */ - d = strjoin(params->prefix[t], "/", *suffix); + d = path_join(params->prefix[t], *suffix); else d = strdup(s); if (!d) { @@ -2800,9 +2800,9 @@ static int compile_suggested_paths(const ExecContext *c, const ExecParameters *p char *e; if (t == EXEC_DIRECTORY_RUNTIME) - e = strjoin(p->prefix[t], "/", *i); + e = path_join(p->prefix[t], *i); else - e = strjoin(p->prefix[t], "/private/", *i); + e = path_join(p->prefix[t], "private", *i); if (!e) return -ENOMEM; @@ -2840,7 +2840,7 @@ static int exec_parameters_get_cgroup_path(const ExecParameters *params, char ** using_subcgroup = FLAGS_SET(params->flags, EXEC_CONTROL_CGROUP|EXEC_CGROUP_DELEGATE|EXEC_IS_CONTROL); if (using_subcgroup) - p = strjoin(params->cgroup_path, "/.control"); + p = path_join(params->cgroup_path, ".control"); else p = strdup(params->cgroup_path); if (!p) diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index bf414e62f1..5c413be08f 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -676,7 +676,7 @@ int config_parse_exec( NULSTR_FOREACH(prefix, DEFAULT_PATH_NULSTR) { _cleanup_free_ char *fullpath = NULL; - fullpath = strjoin(prefix, "/", path); + fullpath = path_join(prefix, path); if (!fullpath) return log_oom(); diff --git a/src/core/main.c b/src/core/main.c index e7f51815f0..a94e6caf85 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -328,7 +328,7 @@ static int parse_confirm_spawn(const char *value, char **console) { else if (is_path(value)) /* on with fully qualified path */ s = strdup(value); else /* on with only a tty file name, not a fully qualified path */ - s = strjoin("/dev/", value); + s = path_join("/dev", value); if (!s) return -ENOMEM; diff --git a/src/core/manager.c b/src/core/manager.c index a3dc5bb40e..78f03a824c 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -1483,7 +1483,7 @@ static void manager_build_unit_path_cache(Manager *m) { FOREACH_DIRENT(de, d, r = -errno; goto fail) { char *p; - p = strjoin(streq(*i, "/") ? "" : *i, "/", de->d_name); + p = path_join(*i, de->d_name); if (!p) { r = -ENOMEM; goto fail; diff --git a/src/core/unit.c b/src/core/unit.c index cab6b44c03..4d777b447d 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -1005,7 +1005,7 @@ int unit_add_exec_dependencies(Unit *u, ExecContext *c) { STRV_FOREACH(dp, c->directories[dt].paths) { _cleanup_free_ char *p; - p = strjoin(u->manager->prefix[dt], "/", *dp); + p = path_join(u->manager->prefix[dt], *dp); if (!p) return -ENOMEM; @@ -4520,7 +4520,7 @@ int unit_make_transient(Unit *u) { (void) mkdir_p_label(u->manager->lookup_paths.transient, 0755); - path = strjoin(u->manager->lookup_paths.transient, "/", u->id); + path = path_join(u->manager->lookup_paths.transient, u->id); if (!path) return -ENOMEM; diff --git a/src/coredump/coredumpctl.c b/src/coredump/coredumpctl.c index d62cbd0323..0529654788 100644 --- a/src/coredump/coredumpctl.c +++ b/src/coredump/coredumpctl.c @@ -776,7 +776,7 @@ static int save_core(sd_journal *j, FILE *file, char **path, bool *unlink_temp) if (r < 0) return log_error_errno(r, "Failed to acquire temporary directory path: %m"); - temp = strjoin(vt, "/coredump-XXXXXX"); + temp = path_join(vt, "coredump-XXXXXX"); if (!temp) return log_oom(); diff --git a/src/debug-generator/debug-generator.c b/src/debug-generator/debug-generator.c index 1b5fb2a28d..5faf8d7ddf 100644 --- a/src/debug-generator/debug-generator.c +++ b/src/debug-generator/debug-generator.c @@ -6,6 +6,7 @@ #include "generator.h" #include "mkdir.h" #include "parse-util.h" +#include "path-util.h" #include "proc-cmdline.h" #include "special.h" #include "string-util.h" @@ -99,7 +100,7 @@ static int generate_mask_symlinks(void) { STRV_FOREACH(u, arg_mask) { _cleanup_free_ char *p = NULL; - p = strjoin(arg_dest, "/", *u); + p = path_join(empty_to_root(arg_dest), *u); if (!p) return log_oom(); diff --git a/src/delta/delta.c b/src/delta/delta.c index 08d8867431..b910074964 100644 --- a/src/delta/delta.c +++ b/src/delta/delta.c @@ -200,7 +200,7 @@ static int enumerate_dir_d( assert(!endswith(drop, "/")); - path = strjoin(toppath, "/", drop); + path = path_join(toppath, drop); if (!path) return -ENOMEM; @@ -230,7 +230,7 @@ static int enumerate_dir_d( if (!endswith(*file, ".conf")) continue; - p = strjoin(path, "/", *file); + p = path_join(path, *file); if (!p) return -ENOMEM; d = p + strlen(toppath) + 1; @@ -347,7 +347,7 @@ static int enumerate_dir( STRV_FOREACH(t, files) { _cleanup_free_ char *p = NULL; - p = strjoin(path, "/", *t); + p = path_join(path, *t); if (!p) return -ENOMEM; @@ -432,7 +432,7 @@ static int process_suffix(const char *suffix, const char *onlyprefix) { if (should_skip_path(p, suffix) > 0) continue; - t = strjoin(p, "/", suffix); + t = path_join(p, suffix); if (!t) { r = -ENOMEM; goto finish; diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c index 6c70054d93..f1db2cbc46 100644 --- a/src/gpt-auto-generator/gpt-auto-generator.c +++ b/src/gpt-auto-generator/gpt-auto-generator.c @@ -181,7 +181,7 @@ static int add_mount( if (r < 0) return log_error_errno(r, "Failed to generate unit name: %m"); - p = strjoin(arg_dest, "/", unit); + p = path_join(empty_to_root(arg_dest), unit); if (!p) return log_oom(); @@ -299,7 +299,7 @@ static int add_swap(const char *path) { if (r < 0) return log_error_errno(r, "Failed to generate unit name: %m"); - unit = strjoin(arg_dest, "/", name); + unit = path_join(empty_to_root(arg_dest), name); if (!unit) return log_oom(); diff --git a/src/import/import-tar.c b/src/import/import-tar.c index 4d0d9254d0..f3eff82a29 100644 --- a/src/import/import-tar.c +++ b/src/import/import-tar.c @@ -211,7 +211,7 @@ static int tar_import_fork_tar(TarImport *i) { assert(!i->temp_path); assert(i->tar_fd < 0); - i->final_path = strjoin(i->image_root, "/", i->local); + i->final_path = path_join(i->image_root, i->local); if (!i->final_path) return log_oom(); diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 2a4fc250c9..50ccc80e87 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -2192,8 +2192,8 @@ int server_init(Server *s) { server_cache_boot_id(s); server_cache_machine_id(s); - s->runtime_storage.path = strjoin("/run/log/journal/", SERVER_MACHINE_ID(s)); - s->system_storage.path = strjoin("/var/log/journal/", SERVER_MACHINE_ID(s)); + s->runtime_storage.path = path_join("/run/log/journal", SERVER_MACHINE_ID(s)); + s->system_storage.path = path_join("/var/log/journal", SERVER_MACHINE_ID(s)); if (!s->runtime_storage.path || !s->system_storage.path) return -ENOMEM; diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c index 40baf2b374..a4f1731613 100644 --- a/src/journal/sd-journal.c +++ b/src/journal/sd-journal.c @@ -1553,10 +1553,7 @@ static int add_directory(sd_journal *j, const char *prefix, const char *dirname) /* Adds a journal file directory to watch. If the directory is already tracked this updates the inotify watch * and reenumerates directory contents */ - if (dirname) - path = strjoin(prefix, "/", dirname); - else - path = strdup(prefix); + path = path_join(prefix, dirname); if (!path) { r = -ENOMEM; goto fail; diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index 1c25ba9dea..978a505610 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -36,6 +36,7 @@ #include "memory-util.h" #include "missing.h" #include "parse-util.h" +#include "path-util.h" #include "process-util.h" #include "string-util.h" #include "strv.h" @@ -3756,7 +3757,7 @@ _public_ int sd_bus_path_encode(const char *prefix, const char *external_id, cha if (!e) return -ENOMEM; - ret = strjoin(prefix, "/", e); + ret = path_join(prefix, e); if (!ret) return -ENOMEM; diff --git a/src/libsystemd/sd-device/device-enumerator.c b/src/libsystemd/sd-device/device-enumerator.c index 4357860170..5b54641213 100644 --- a/src/libsystemd/sd-device/device-enumerator.c +++ b/src/libsystemd/sd-device/device-enumerator.c @@ -752,7 +752,7 @@ static int parent_crawl_children(sd_device_enumerator *enumerator, const char *p if (dent->d_type != DT_DIR) continue; - child = strjoin(path, "/", dent->d_name); + child = path_join(path, dent->d_name); if (!child) return -ENOMEM; diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index b1572981b1..773be6ae1e 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -167,7 +167,7 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) { "sd-device: Canonicalized path '%s' does not starts with sysfs mount point '%s'", syspath, real_sys); - new_syspath = strjoin("/sys/", p); + new_syspath = path_join("/sys", p); if (!new_syspath) return -ENOMEM; diff --git a/src/libsystemd/sd-event/test-event.c b/src/libsystemd/sd-event/test-event.c index 6fd6d9f0b0..224ea93a77 100644 --- a/src/libsystemd/sd-event/test-event.c +++ b/src/libsystemd/sd-event/test-event.c @@ -10,6 +10,7 @@ #include "log.h" #include "macro.h" #include "parse-util.h" +#include "path-util.h" #include "process-util.h" #include "rm-rf.h" #include "signal-util.h" @@ -464,7 +465,7 @@ static void test_inotify(unsigned n_create_events) { _cleanup_free_ char *z; xsprintf(buf, "%u", i); - assert_se(z = strjoin(p, "/", buf)); + assert_se(z = path_join(p, buf)); assert_se(touch(z) >= 0); } diff --git a/src/libsystemd/sd-path/sd-path.c b/src/libsystemd/sd-path/sd-path.c index 9949c23802..12ff30ef86 100644 --- a/src/libsystemd/sd-path/sd-path.c +++ b/src/libsystemd/sd-path/sd-path.c @@ -58,10 +58,7 @@ static int from_home_dir(const char *envname, const char *suffix, char **buffer, if (r < 0) return r; - if (endswith(h, "/")) - cc = strappend(h, suffix); - else - cc = strjoin(h, "/", suffix); + cc = path_join(h, suffix); if (!cc) return -ENOMEM; @@ -328,8 +325,9 @@ static int get_path(uint64_t type, char **buffer, const char **ret) { } _public_ int sd_path_home(uint64_t type, const char *suffix, char **path) { - char *buffer = NULL, *cc; + _cleanup_free_ char *buffer = NULL; const char *ret; + char *cc; int r; assert_return(path, -EINVAL); @@ -354,7 +352,7 @@ _public_ int sd_path_home(uint64_t type, const char *suffix, char **path) { if (!buffer) return -ENOMEM; - *path = buffer; + *path = TAKE_PTR(buffer); return 0; } @@ -369,23 +367,16 @@ _public_ int sd_path_home(uint64_t type, const char *suffix, char **path) { return -ENOMEM; } - *path = buffer; + *path = TAKE_PTR(buffer); return 0; } suffix += strspn(suffix, "/"); - - if (endswith(ret, "/")) - cc = strappend(ret, suffix); - else - cc = strjoin(ret, "/", suffix); - - free(buffer); - + cc = path_join(ret, suffix); if (!cc) return -ENOMEM; - *path = cc; + *path = TAKE_PTR(cc); return 0; } @@ -443,10 +434,7 @@ static int search_from_environment( if (!h && home_suffix) { e = secure_getenv("HOME"); if (e && path_is_absolute(e)) { - if (endswith(e, "/")) - h = strappend(e, home_suffix); - else - h = strjoin(e, "/", home_suffix); + h = path_join(e, home_suffix); if (!h) { strv_free(l); @@ -621,12 +609,7 @@ _public_ int sd_path_search(uint64_t type, const char *suffix, char ***paths) { j = n; STRV_FOREACH(i, l) { - - if (endswith(*i, "/")) - *j = strappend(*i, suffix); - else - *j = strjoin(*i, "/", suffix); - + *j = path_join(*i, suffix); if (!*j) return -ENOMEM; diff --git a/src/mount/mount-tool.c b/src/mount/mount-tool.c index 4e9ab762e9..457ba4ea16 100644 --- a/src/mount/mount-tool.c +++ b/src/mount/mount-tool.c @@ -789,7 +789,7 @@ static int find_loop_device(const char *backing_file, char **loop_dev) { if (!startswith(de->d_name, "loop")) continue; - sys = strjoin("/sys/devices/virtual/block/", de->d_name, "/loop/backing_file"); + sys = path_join("/sys/devices/virtual/block", de->d_name, "loop/backing_file"); if (!sys) return -ENOMEM; @@ -802,7 +802,7 @@ static int find_loop_device(const char *backing_file, char **loop_dev) { if (files_same(fname, backing_file, 0) <= 0) continue; - l = strjoin("/dev/", de->d_name); + l = path_join("/dev", de->d_name); if (!l) return -ENOMEM; @@ -1125,7 +1125,7 @@ static int acquire_mount_where(sd_device *d) { if (!filename_is_valid(escaped)) return 0; - arg_mount_where = strjoin("/run/media/system/", escaped); + arg_mount_where = path_join("/run/media/system", escaped); } else arg_mount_where = strdup(v); @@ -1257,7 +1257,7 @@ static int discover_loop_backing_file(void) { return -EINVAL; } - arg_mount_where = strjoin("/run/media/system/", escaped); + arg_mount_where = path_join("/run/media/system", escaped); if (!arg_mount_where) return log_oom(); diff --git a/src/nspawn/nspawn-mount.c b/src/nspawn/nspawn-mount.c index e0740a6cc4..82b7068fcd 100644 --- a/src/nspawn/nspawn-mount.c +++ b/src/nspawn/nspawn-mount.c @@ -145,7 +145,7 @@ int custom_mount_prepare_all(const char *dest, CustomMount *l, size_t n) { return log_error_errno(errno, "Failed to acquire temporary directory: %m"); } - m->source = strjoin(m->rm_rf_tmpdir, "/src"); + m->source = path_join(m->rm_rf_tmpdir, "src"); if (!m->source) return log_oom(); diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index e7f8cf389f..b3f4be0e6e 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -1934,7 +1934,7 @@ static int copy_devnodes(const char *dest) { if (r < 0) return log_error_errno(r, "chown() of device node %s failed: %m", to); - dn = strjoin("/dev/", S_ISCHR(st.st_mode) ? "char" : "block"); + dn = path_join("/dev", S_ISCHR(st.st_mode) ? "char" : "block"); if (!dn) return log_oom(); @@ -2596,7 +2596,7 @@ static int determine_names(void) { * search for a machine, but instead create a new one * in /var/lib/machine. */ - arg_directory = strjoin("/var/lib/machines/", arg_machine); + arg_directory = path_join("/var/lib/machines", arg_machine); if (!arg_directory) return log_oom(); } @@ -3991,7 +3991,7 @@ static int load_settings(void) { FOREACH_STRING(i, "/etc/systemd/nspawn", "/run/systemd/nspawn") { _cleanup_free_ char *j = NULL; - j = strjoin(i, "/", fn); + j = path_join(i, fn); if (!j) return log_oom(); diff --git a/src/portable/portable.c b/src/portable/portable.c index 7d39d7b5f3..8202a8ca2e 100644 --- a/src/portable/portable.c +++ b/src/portable/portable.c @@ -325,7 +325,7 @@ static int extract_now( return -ENOMEM; fd = -1; - m->source = strjoin(resolved, "/", de->d_name); + m->source = path_join(resolved, de->d_name); if (!m->source) return -ENOMEM; @@ -691,7 +691,7 @@ static int install_chroot_dropin( assert(m); assert(dropin_dir); - dropin = strjoin(dropin_dir, "/20-portable.conf"); + dropin = path_join(dropin_dir, "20-portable.conf"); if (!dropin) return -ENOMEM; @@ -778,7 +778,7 @@ static int install_profile_dropin( return 0; } - dropin = strjoin(dropin_dir, "/10-profile.conf"); + dropin = path_join(dropin_dir, "10-profile.conf"); if (!dropin) return -ENOMEM; diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index 81acff4602..b3b05872e9 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -31,6 +31,7 @@ #include "mountpoint-util.h" #include "nsflags.h" #include "parse-util.h" +#include "path-util.h" #include "proc-cmdline.h" #include "rlimit-util.h" #include "stdio-util.h" @@ -1552,7 +1553,7 @@ int bus_path_encode_unique(sd_bus *b, const char *prefix, const char *sender_id, if (!external_label) return -ENOMEM; - p = strjoin(prefix, "/", sender_label, "/", external_label); + p = path_join(prefix, sender_label, external_label); if (!p) return -ENOMEM; diff --git a/src/shared/cgroup-show.c b/src/shared/cgroup-show.c index e6fdcfa277..465e38c4fb 100644 --- a/src/shared/cgroup-show.c +++ b/src/shared/cgroup-show.c @@ -148,7 +148,7 @@ int show_cgroup_by_path( while ((r = cg_read_subgroup(d, &gn)) > 0) { _cleanup_free_ char *k = NULL; - k = strjoin(fn, "/", gn); + k = path_join(fn, gn); free(gn); if (!k) return -ENOMEM; diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index 95ee7efa92..f930c02673 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -994,7 +994,7 @@ static int make_dm_name_and_node(const void *original_node, const char *suffix, if (!filename_is_valid(name)) return -EINVAL; - node = strjoin(crypt_get_dir(), "/", name); + node = path_join(crypt_get_dir(), name); if (!node) return -ENOMEM; diff --git a/src/shared/install.c b/src/shared/install.c index b13b1f6d9e..105412bc8f 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -1424,7 +1424,7 @@ static int unit_file_search( STRV_FOREACH(p, paths->search_path) { _cleanup_free_ char *path = NULL; - path = strjoin(*p, "/", info->name); + path = path_join(*p, info->name); if (!path) return -ENOMEM; @@ -1447,7 +1447,7 @@ static int unit_file_search( STRV_FOREACH(p, paths->search_path) { _cleanup_free_ char *path = NULL; - path = strjoin(*p, "/", template); + path = path_join(*p, template); if (!path) return -ENOMEM; @@ -1840,7 +1840,7 @@ static int install_info_symlink_link( if (r > 0) return 0; - path = strjoin(config_path, "/", i->name); + path = path_join(config_path, i->name); if (!path) return -ENOMEM; @@ -2379,7 +2379,7 @@ int unit_file_revert( STRV_FOREACH(j, fs) { _cleanup_free_ char *t = NULL; - t = strjoin(*i, "/", *j); + t = path_join(*i, *j); if (!t) return -ENOMEM; diff --git a/src/shared/machine-image.c b/src/shared/machine-image.c index 55e5f08f91..ee086e35b4 100644 --- a/src/shared/machine-image.c +++ b/src/shared/machine-image.c @@ -146,10 +146,7 @@ static int image_new( if (!i->name) return -ENOMEM; - if (path) - i->path = strjoin(path, "/", filename); - else - i->path = strdup(filename); + i->path = path_join(path, filename); if (!i->path) return -ENOMEM; diff --git a/src/shared/path-lookup.c b/src/shared/path-lookup.c index 1a005970f2..6494210ee9 100644 --- a/src/shared/path-lookup.c +++ b/src/shared/path-lookup.c @@ -303,7 +303,7 @@ static int acquire_transient_dir( return -EOPNOTSUPP; if (tempdir) - transient = strjoin(tempdir, "/transient"); + transient = path_join(tempdir, "transient"); else if (scope == UNIT_FILE_SYSTEM) transient = strdup("/run/systemd/transient"); else diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 1158914fb4..31bc776449 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -7329,12 +7329,12 @@ static int get_file_to_edit( assert(name); assert(ret_path); - path = strjoin(paths->persistent_config, "/", name); + path = path_join(paths->persistent_config, name); if (!path) return log_oom(); if (arg_runtime) { - run = strjoin(paths->runtime_config, "/", name); + run = path_join(paths->runtime_config, name); if (!run) return log_oom(); } diff --git a/src/sysv-generator/sysv-generator.c b/src/sysv-generator/sysv-generator.c index 514b6e0169..13a9a77e81 100644 --- a/src/sysv-generator/sysv-generator.c +++ b/src/sysv-generator/sysv-generator.c @@ -784,7 +784,7 @@ static int enumerate_sysv(const LookupPaths *lp, Hashmap *all_services) { continue; } - fpath = strjoin(*path, "/", de->d_name); + fpath = path_join(*path, de->d_name); if (!fpath) return log_oom(); @@ -829,7 +829,7 @@ static int set_dependencies_from_rcnd(const LookupPaths *lp, Hashmap *all_servic _cleanup_free_ char *path = NULL; struct dirent *de; - path = strjoin(*p, "/", rcnd_table[i].path); + path = path_join(*p, rcnd_table[i].path); if (!path) { r = log_oom(); goto finish; @@ -859,7 +859,7 @@ static int set_dependencies_from_rcnd(const LookupPaths *lp, Hashmap *all_servic if (a < 0 || b < 0) continue; - fpath = strjoin(*p, "/", de->d_name); + fpath = path_join(*p, de->d_name); if (!fpath) { r = log_oom(); goto finish; diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c index 6abc9bee39..b82fd88497 100644 --- a/src/udev/udev-builtin-net_id.c +++ b/src/udev/udev-builtin-net_id.c @@ -139,7 +139,7 @@ static int get_virtfn_info(sd_device *dev, struct netnames *names, struct virtfn if (!startswith(dent->d_name, "virtfn")) continue; - virtfn_link_file = strjoin(physfn_pci_syspath, "/", dent->d_name); + virtfn_link_file = path_join(physfn_pci_syspath, dent->d_name); if (!virtfn_link_file) return -ENOMEM; |