* 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;
if (old_child_fd < 0)
return -errno;
- np = strjoin(subvolume, "/", ino_args.name);
+ np = path_join(subvolume, ino_args.name);
if (!np)
return -ENOMEM;
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;
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;
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;
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;
else if (!path)
t = strdup(suffix);
else
- t = strjoin(path, "/", suffix);
+ t = path_join(path, suffix);
if (!t)
return -ENOMEM;
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;
key = p;
} else {
- p = strjoin(dirpath, "/", de->d_name);
+ p = path_join(dirpath, de->d_name);
if (!p)
return -ENOMEM;
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;
_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;
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) {
if (!path_is_absolute(element))
continue;
- j = strjoin(element, "/", name);
+ j = path_join(element, name);
if (!j)
return -ENOMEM;
if (r < 0)
return r;
- p = strjoin(tmp, "/XXXXXX");
+ p = path_join(tmp, "XXXXXX");
}
if (!p)
return -ENOMEM;
#include "alloc-util.h"
#include "busctl-introspect.h"
+#include "path-util.h"
#include "string-util.h"
#include "util.h"
#include "xml.h"
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();
}
controller = c ?: SYSTEMD_CGROUP_CONTROLLER;
if (p) {
- j = strjoin(root, "/", p);
+ j = path_join(root, p);
if (!j)
return log_oom();
if (r == 0)
break;
- p = strjoin(path, "/", fn);
+ p = path_join(path, fn);
if (!p)
return -ENOMEM;
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) {
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)
if (e) {
char *z;
- z = strjoin("/run/", e);
+ z = path_join("/run", e);
if (!z)
return log_oom();
if (r == 0)
break;
- j = strjoin(p, "/", g);
+ j = path_join(p, g);
if (!j)
return -ENOMEM;
* 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;
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;
/* 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) {
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;
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)
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();
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;
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;
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;
(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;
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();
#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"
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();
assert(!endswith(drop, "/"));
- path = strjoin(toppath, "/", drop);
+ path = path_join(toppath, drop);
if (!path)
return -ENOMEM;
if (!endswith(*file, ".conf"))
continue;
- p = strjoin(path, "/", *file);
+ p = path_join(path, *file);
if (!p)
return -ENOMEM;
d = p + strlen(toppath) + 1;
STRV_FOREACH(t, files) {
_cleanup_free_ char *p = NULL;
- p = strjoin(path, "/", *t);
+ p = path_join(path, *t);
if (!p)
return -ENOMEM;
if (should_skip_path(p, suffix))
continue;
- t = strjoin(p, "/", suffix);
+ t = path_join(p, suffix);
if (!t) {
r = -ENOMEM;
goto finish;
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();
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();
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();
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;
/* 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;
#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"
if (!e)
return -ENOMEM;
- ret = strjoin(prefix, "/", e);
+ ret = path_join(prefix, e);
if (!ret)
return -ENOMEM;
if (dent->d_type != DT_DIR)
continue;
- child = strjoin(path, "/", dent->d_name);
+ child = path_join(path, dent->d_name);
if (!child)
return -ENOMEM;
"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;
#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"
_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);
}
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;
}
suffix += strspn(suffix, "/");
-
- if (endswith(ret, "/"))
- cc = strappend(ret, suffix);
- else
- cc = strjoin(ret, "/", suffix);
+ cc = path_join(ret, suffix);
free(buffer);
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);
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;
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;
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;
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);
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();
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();
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();
* 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();
}
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();
return -ENOMEM;
fd = -1;
- m->source = strjoin(resolved, "/", de->d_name);
+ m->source = path_join(resolved, de->d_name);
if (!m->source)
return -ENOMEM;
assert(m);
assert(dropin_dir);
- dropin = strjoin(dropin_dir, "/20-portable.conf");
+ dropin = path_join(dropin_dir, "20-portable.conf");
if (!dropin)
return -ENOMEM;
return 0;
}
- dropin = strjoin(dropin_dir, "/10-profile.conf");
+ dropin = path_join(dropin_dir, "10-profile.conf");
if (!dropin)
return -ENOMEM;
#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"
if (!external_label)
return -ENOMEM;
- p = strjoin(prefix, "/", sender_label, "/", external_label);
+ p = path_join(prefix, sender_label, external_label);
if (!p)
return -ENOMEM;
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;
if (!filename_is_valid(name))
return -EINVAL;
- node = strjoin(crypt_get_dir(), "/", name);
+ node = path_join(crypt_get_dir(), name);
if (!node)
return -ENOMEM;
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;
STRV_FOREACH(p, paths->search_path) {
_cleanup_free_ char *path = NULL;
- path = strjoin(*p, "/", template);
+ path = path_join(*p, template);
if (!path)
return -ENOMEM;
if (r > 0)
return 0;
- path = strjoin(config_path, "/", i->name);
+ path = path_join(config_path, i->name);
if (!path)
return -ENOMEM;
STRV_FOREACH(j, fs) {
_cleanup_free_ char *t = NULL;
- t = strjoin(*i, "/", *j);
+ t = path_join(*i, *j);
if (!t)
return -ENOMEM;
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;
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
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();
}
continue;
}
- fpath = strjoin(*path, "/", de->d_name);
+ fpath = path_join(*path, de->d_name);
if (!fpath)
return log_oom();
_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;
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;
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;