summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2019-06-25 09:27:01 +0200
committerGitHub <noreply@github.com>2019-06-25 09:27:01 +0200
commit05b2ace14732fd4401c856f7c375a311ac6f2af1 (patch)
tree419344328d3208fd7de780d73ef9f56f2a333aa1
parentMerge pull request #12871 from keszybz/various-printing-fixes (diff)
parenttree-wide: replace strjoina() with prefix_roota() (diff)
downloadsystemd-05b2ace14732fd4401c856f7c375a311ac6f2af1.tar.xz
systemd-05b2ace14732fd4401c856f7c375a311ac6f2af1.zip
Merge pull request #12870 from yuwata/tree-wide-further-path-join-cleanups
tree-wide: further path_join() and path_joina() cleanups
-rw-r--r--src/basic/fs-util.c4
-rw-r--r--src/basic/path-util.h4
-rw-r--r--src/boot/bootctl.c24
-rw-r--r--src/core/cgroup.c2
-rw-r--r--src/delta/delta.c5
-rw-r--r--src/gpt-auto-generator/gpt-auto-generator.c4
-rw-r--r--src/import/import-common.c2
-rw-r--r--src/import/import-fs.c2
-rw-r--r--src/import/pull-common.c2
-rw-r--r--src/journal/sd-journal.c4
-rw-r--r--src/libsystemd/sd-device/device-private.c5
-rw-r--r--src/libsystemd/sd-device/sd-device.c7
-rw-r--r--src/nspawn/nspawn.c2
-rw-r--r--src/portable/portable.c6
-rw-r--r--src/shared/generator.c8
-rw-r--r--src/systemctl/systemctl.c4
-rw-r--r--src/sysv-generator/sysv-generator.c4
-rw-r--r--src/test/test-path-util.c3
-rw-r--r--src/tmpfiles/tmpfiles.c2
-rw-r--r--src/veritysetup/veritysetup-generator.c5
20 files changed, 50 insertions, 49 deletions
diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c
index 14d3725709..3ed8e2c8a9 100644
--- a/src/basic/fs-util.c
+++ b/src/basic/fs-util.c
@@ -980,9 +980,9 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags,
/* Prefix what's left to do with what we just read, and start the loop again, but
* remain in the current directory. */
- joined = strjoin(destination, todo);
+ joined = path_join(destination, todo);
} else
- joined = strjoin("/", destination, todo);
+ joined = path_join("/", destination, todo);
if (!joined)
return -ENOMEM;
diff --git a/src/basic/path-util.h b/src/basic/path-util.h
index af4878b325..4a1ed0a1a8 100644
--- a/src/basic/path-util.h
+++ b/src/basic/path-util.h
@@ -117,7 +117,7 @@ int mkfs_exists(const char *fstype);
_slash = strrchr((prefix), '/'))
/* Similar to path_join(), but only works for two components, and only the first one may be NULL and returns
- * an alloca() buffer, or possibly a const pointer into the path parameter */
+ * an alloca() buffer, or possibly a const pointer into the path parameter. */
#define prefix_roota(root, path) \
({ \
const char* _path = (path), *_root = (root), *_ret; \
@@ -125,7 +125,7 @@ int mkfs_exists(const char *fstype);
size_t _l; \
while (_path[0] == '/' && _path[1] == '/') \
_path ++; \
- if (empty_or_root(_root)) \
+ if (isempty(_root)) \
_ret = _path; \
else { \
_l = strlen(_root) + 1 + strlen(_path) + 1; \
diff --git a/src/boot/bootctl.c b/src/boot/bootctl.c
index 2f195f1014..368dd88f5f 100644
--- a/src/boot/bootctl.c
+++ b/src/boot/bootctl.c
@@ -166,13 +166,13 @@ finish:
static int enumerate_binaries(const char *esp_path, const char *path, const char *prefix) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
+ const char *p;
int c = 0, r;
- char *p;
assert(esp_path);
assert(path);
- p = strjoina(esp_path, "/", path);
+ p = prefix_roota(esp_path, path);
d = opendir(p);
if (!d) {
if (errno == ENOENT)
@@ -766,7 +766,7 @@ static int install_variables(const char *esp_path,
uint32_t part, uint64_t pstart, uint64_t psize,
sd_id128_t uuid, const char *path,
bool first) {
- char *p;
+ const char *p;
uint16_t slot;
int r;
@@ -775,7 +775,7 @@ static int install_variables(const char *esp_path,
return 0;
}
- p = strjoina(esp_path, path);
+ p = prefix_roota(esp_path, path);
if (access(p, F_OK) < 0) {
if (errno == ENOENT)
return 0;
@@ -804,12 +804,12 @@ static int install_variables(const char *esp_path,
}
static int remove_boot_efi(const char *esp_path) {
- char *p;
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
+ const char *p;
int r, c = 0;
- p = strjoina(esp_path, "/EFI/BOOT");
+ p = prefix_roota(esp_path, "/EFI/BOOT");
d = opendir(p);
if (!d) {
if (errno == ENOENT)
@@ -850,9 +850,9 @@ static int remove_boot_efi(const char *esp_path) {
}
static int rmdir_one(const char *prefix, const char *suffix) {
- char *p;
+ const char *p;
- p = strjoina(prefix, "/", suffix);
+ p = prefix_roota(prefix, suffix);
if (rmdir(p) < 0) {
bool ignore = IN_SET(errno, ENOENT, ENOTEMPTY);
@@ -882,10 +882,10 @@ static int remove_esp_subdirs(const char *esp_path) {
}
static int remove_binaries(const char *esp_path) {
- char *p;
+ const char *p;
int r, q;
- p = strjoina(esp_path, "/EFI/systemd");
+ p = prefix_roota(esp_path, "/EFI/systemd");
r = rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL);
q = remove_boot_efi(esp_path);
@@ -900,7 +900,7 @@ static int remove_loader_config(const char *esp_path) {
assert(esp_path);
- p = strjoina(esp_path, "/loader/loader.conf");
+ p = prefix_roota(esp_path, "/loader/loader.conf");
if (unlink(p) < 0) {
log_full_errno(errno == ENOENT ? LOG_DEBUG : LOG_ERR, errno, "Failed to unlink file \"%s\": %m", p);
if (errno != ENOENT)
@@ -945,7 +945,7 @@ static int install_loader_config(const char *esp_path, sd_id128_t machine_id) {
const char *p;
int r, fd;
- p = strjoina(esp_path, "/loader/loader.conf");
+ p = prefix_roota(esp_path, "/loader/loader.conf");
if (access(p, F_OK) >= 0) /* Silently skip creation if the file already exists (early check) */
return 0;
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index 4b16bb3367..1ed5723892 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -1926,7 +1926,7 @@ int unit_attach_pids_to_cgroup(Unit *u, Set *pids, const char *suffix_path) {
if (isempty(suffix_path))
p = u->cgroup_path;
else
- p = strjoina(u->cgroup_path, "/", suffix_path);
+ p = prefix_roota(u->cgroup_path, suffix_path);
delegated_mask = unit_get_delegate_mask(u);
diff --git a/src/delta/delta.c b/src/delta/delta.c
index b910074964..bc11aa828a 100644
--- a/src/delta/delta.c
+++ b/src/delta/delta.c
@@ -374,10 +374,9 @@ static int enumerate_dir(
static int should_skip_path(const char *prefix, const char *suffix) {
#if HAVE_SPLIT_USR
_cleanup_free_ char *target = NULL;
- const char *p;
- char *dirname;
+ const char *dirname, *p;
- dirname = strjoina(prefix, "/", suffix);
+ dirname = prefix_roota(prefix, suffix);
if (chase_symlinks(dirname, NULL, 0, &target) < 0)
return false;
diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c
index f1db2cbc46..f6e37670b9 100644
--- a/src/gpt-auto-generator/gpt-auto-generator.c
+++ b/src/gpt-auto-generator/gpt-auto-generator.c
@@ -71,7 +71,7 @@ static int add_cryptsetup(const char *id, const char *what, bool rw, bool requir
if (!what_escaped)
return log_oom();
- p = strjoina(arg_dest, "/", n);
+ p = prefix_roota(arg_dest, n);
f = fopen(p, "wxe");
if (!f)
return log_error_errno(errno, "Failed to create unit file %s: %m", p);
@@ -360,7 +360,7 @@ static int add_automount(
if (r < 0)
return log_error_errno(r, "Failed to generate unit name: %m");
- p = strjoina(arg_dest, "/", unit);
+ p = prefix_roota(arg_dest, unit);
f = fopen(p, "wxe");
if (!f)
return log_error_errno(errno, "Failed to create unit file %s: %m", unit);
diff --git a/src/import/import-common.c b/src/import/import-common.c
index 1f63ebb761..2f27dda76b 100644
--- a/src/import/import-common.c
+++ b/src/import/import-common.c
@@ -213,7 +213,7 @@ int import_mangle_os_tree(const char *path) {
return 0;
}
- joined = strjoina(path, "/", child);
+ joined = prefix_roota(path, child);
r = path_is_os_tree(joined);
if (r == -ENOTDIR) {
log_debug("Directory '%s' does not look like a directory tree, and contains a single regular file only, leaving as it is.", path);
diff --git a/src/import/import-fs.c b/src/import/import-fs.c
index abb4efac99..f8f3a23206 100644
--- a/src/import/import-fs.c
+++ b/src/import/import-fs.c
@@ -161,7 +161,7 @@ static int import_fs(int argc, char *argv[], void *userdata) {
log_info("Importing '%s', saving as '%s'.", strempty(pretty), local);
}
- final_path = strjoina(arg_image_root, "/", local);
+ final_path = prefix_roota(arg_image_root, local);
r = tempfn_random(final_path, NULL, &temp_path);
if (r < 0)
diff --git a/src/import/pull-common.c b/src/import/pull-common.c
index 62b52309a4..249ea533e6 100644
--- a/src/import/pull-common.c
+++ b/src/import/pull-common.c
@@ -120,7 +120,7 @@ int pull_make_local_copy(const char *final, const char *image_root, const char *
if (!image_root)
image_root = "/var/lib/machines";
- p = strjoina(image_root, "/", local);
+ p = prefix_roota(image_root, local);
if (force_local)
(void) rm_rf(p, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_SUBVOLUME);
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index a4f1731613..82b180b019 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -1376,7 +1376,7 @@ static int add_file_by_name(
if (!file_type_wanted(j->flags, filename))
return 0;
- path = strjoina(prefix, "/", filename);
+ path = prefix_roota(prefix, filename);
return add_any_file(j, -1, path);
}
@@ -1392,7 +1392,7 @@ static void remove_file_by_name(
assert(prefix);
assert(filename);
- path = strjoina(prefix, "/", filename);
+ path = prefix_roota(prefix, filename);
f = ordered_hashmap_get(j->files, path);
if (!f)
return;
diff --git a/src/libsystemd/sd-device/device-private.c b/src/libsystemd/sd-device/device-private.c
index a0855001e3..731b0ed0a7 100644
--- a/src/libsystemd/sd-device/device-private.c
+++ b/src/libsystemd/sd-device/device-private.c
@@ -609,8 +609,7 @@ void device_set_watch_handle(sd_device *device, int handle) {
int device_rename(sd_device *device, const char *name) {
_cleanup_free_ char *dirname = NULL;
- char *new_syspath;
- const char *interface;
+ const char *new_syspath, *interface;
int r;
assert(device);
@@ -620,7 +619,7 @@ int device_rename(sd_device *device, const char *name) {
if (!dirname)
return -ENOMEM;
- new_syspath = strjoina(dirname, "/", name);
+ new_syspath = prefix_roota(dirname, name);
/* the user must trust that the new name is correct */
r = device_set_syspath(device, new_syspath, false);
diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c
index 7d5d241965..617d6de667 100644
--- a/src/libsystemd/sd-device/sd-device.c
+++ b/src/libsystemd/sd-device/sd-device.c
@@ -1739,8 +1739,7 @@ static int device_get_sysattr_value(sd_device *device, const char *_key, const c
* with a NULL value in the cache, otherwise the returned string is stored */
_public_ int sd_device_get_sysattr_value(sd_device *device, const char *sysattr, const char **_value) {
_cleanup_free_ char *value = NULL;
- const char *syspath, *cached_value = NULL;
- char *path;
+ const char *path, *syspath, *cached_value = NULL;
struct stat statbuf;
int r;
@@ -1767,7 +1766,7 @@ _public_ int sd_device_get_sysattr_value(sd_device *device, const char *sysattr,
if (r < 0)
return r;
- path = strjoina(syspath, "/", sysattr);
+ path = prefix_roota(syspath, sysattr);
r = lstat(path, &statbuf);
if (r < 0) {
/* remember that we could not access the sysattr */
@@ -1842,7 +1841,7 @@ _public_ int sd_device_set_sysattr_value(sd_device *device, const char *sysattr,
if (r < 0)
return r;
- path = strjoina(syspath, "/", sysattr);
+ path = prefix_roota(syspath, sysattr);
len = strlen(_value);
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index b3f4be0e6e..7ada411636 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -1949,7 +1949,7 @@ static int copy_devnodes(const char *dest) {
if (!prefixed)
return log_oom();
- t = strjoin("../", d);
+ t = path_join("..", d);
if (!t)
return log_oom();
diff --git a/src/portable/portable.c b/src/portable/portable.c
index 8202a8ca2e..4956ae7310 100644
--- a/src/portable/portable.c
+++ b/src/portable/portable.c
@@ -653,10 +653,10 @@ static int portable_changes_add_with_prefix(
return 0;
if (prefix) {
- path = strjoina(prefix, "/", path);
+ path = prefix_roota(prefix, path);
if (source)
- source = strjoina(prefix, "/", source);
+ source = prefix_roota(prefix, source);
}
return portable_changes_add(changes, n_changes, type, path, source);
@@ -847,7 +847,7 @@ static int attach_unit_file(
} else
(void) portable_changes_add(changes, n_changes, PORTABLE_MKDIR, where, NULL);
- path = strjoina(where, "/", m->name);
+ path = prefix_roota(where, m->name);
dropin_dir = strjoin(path, ".d");
if (!dropin_dir)
return -ENOMEM;
diff --git a/src/shared/generator.c b/src/shared/generator.c
index 0a5413ce04..7273fde186 100644
--- a/src/shared/generator.c
+++ b/src/shared/generator.c
@@ -31,7 +31,7 @@ int generator_open_unit_file(
FILE *f;
int r;
- unit = strjoina(dest, "/", name);
+ unit = prefix_roota(dest, name);
r = fopen_unlocked(unit, "wxe", &f);
if (r < 0) {
@@ -319,7 +319,7 @@ int generator_hook_up_mkswap(
return log_error_errno(r, "Failed to make unit instance name from path \"%s\": %m",
node);
- unit_file = strjoina(dir, "/", unit);
+ unit_file = prefix_roota(dir, unit);
log_debug("Creating %s", unit_file);
escaped = cescape(node);
@@ -394,7 +394,7 @@ int generator_hook_up_mkfs(
return log_error_errno(r, "Failed to make unit instance name from path \"%s\": %m",
node);
- unit_file = strjoina(dir, "/", unit);
+ unit_file = prefix_roota(dir, unit);
log_debug("Creating %s", unit_file);
escaped = cescape(node);
@@ -466,7 +466,7 @@ int generator_hook_up_growfs(
return log_error_errno(r, "Failed to make unit name from path \"%s\": %m",
where);
- unit_file = strjoina(dir, "/", unit);
+ unit_file = prefix_roota(dir, unit);
log_debug("Creating %s", unit_file);
f = fopen(unit_file, "wxe");
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index cf0c612923..dbe442d7da 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -6287,8 +6287,8 @@ static int switch_root(int argc, char *argv[], void *userdata) {
if (init) {
const char *root_systemd_path = NULL, *root_init_path = NULL;
- root_systemd_path = strjoina(root, "/" SYSTEMD_BINARY_PATH);
- root_init_path = strjoina(root, "/", init);
+ root_systemd_path = prefix_roota(root, "/" SYSTEMD_BINARY_PATH);
+ root_init_path = prefix_roota(root, init);
/* If the passed init is actually the same as the
* systemd binary, then let's suppress it. */
diff --git a/src/sysv-generator/sysv-generator.c b/src/sysv-generator/sysv-generator.c
index 13a9a77e81..28f8ab301b 100644
--- a/src/sysv-generator/sysv-generator.c
+++ b/src/sysv-generator/sysv-generator.c
@@ -87,7 +87,7 @@ static int add_alias(const char *service, const char *alias) {
assert(service);
assert(alias);
- link = strjoina(arg_dest, "/", alias);
+ link = prefix_roota(arg_dest, alias);
r = symlink(service, link);
if (r < 0) {
@@ -116,7 +116,7 @@ static int generate_unit_file(SysvStub *s) {
if (!path_escaped)
return log_oom();
- unit = strjoina(arg_dest, "/", s->name);
+ unit = prefix_roota(arg_dest, s->name);
/* We might already have a symlink with the same name from a Provides:,
* or from backup files like /etc/init.d/foo.bak. Real scripts always win,
diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c
index 7ef30ffc00..3e91c87eea 100644
--- a/src/test/test-path-util.c
+++ b/src/test/test-path-util.c
@@ -403,6 +403,9 @@ static void test_prefix_root(void) {
test_prefix_root_one("///", "/foo", "/foo");
test_prefix_root_one("/", "////foo", "/foo");
test_prefix_root_one(NULL, "////foo", "/foo");
+ test_prefix_root_one("/", "foo", "/foo");
+ test_prefix_root_one("", "foo", "foo");
+ test_prefix_root_one(NULL, "foo", "foo");
test_prefix_root_one("/foo", "/bar", "/foo/bar");
test_prefix_root_one("/foo", "bar", "/foo/bar");
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 334e3fb5f4..7b091006ea 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -2471,7 +2471,7 @@ static int patch_var_run(const char *fname, unsigned line, char **path) {
if (isempty(k)) /* Don't complain about other paths than /var/run, and not about /var/run itself either. */
return 0;
- n = strjoin("/run/", k);
+ n = path_join("/run", k);
if (!n)
return log_oom();
diff --git a/src/veritysetup/veritysetup-generator.c b/src/veritysetup/veritysetup-generator.c
index 65a4e7b0fd..f2b74f3dc1 100644
--- a/src/veritysetup/veritysetup-generator.c
+++ b/src/veritysetup/veritysetup-generator.c
@@ -16,6 +16,7 @@
#include "main-func.h"
#include "mkdir.h"
#include "parse-util.h"
+#include "path-util.h"
#include "proc-cmdline.h"
#include "specifier.h"
#include "string-util.h"
@@ -188,7 +189,7 @@ static int determine_devices(void) {
if (!arg_data_what) {
memcpy(&root_uuid, m, sizeof(root_uuid));
- arg_data_what = strjoin("/dev/disk/by-partuuid/", id128_to_uuid_string(root_uuid, ids));
+ arg_data_what = path_join("/dev/disk/by-partuuid", id128_to_uuid_string(root_uuid, ids));
if (!arg_data_what)
return log_oom();
}
@@ -196,7 +197,7 @@ static int determine_devices(void) {
if (!arg_hash_what) {
memcpy(&verity_uuid, (uint8_t*) m + l - sizeof(verity_uuid), sizeof(verity_uuid));
- arg_hash_what = strjoin("/dev/disk/by-partuuid/", id128_to_uuid_string(verity_uuid, ids));
+ arg_hash_what = path_join("/dev/disk/by-partuuid", id128_to_uuid_string(verity_uuid, ids));
if (!arg_hash_what)
return log_oom();
}