]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: replace strjoina() with prefix_roota() 12870/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 24 Jun 2019 15:24:23 +0000 (00:24 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 24 Jun 2019 16:31:26 +0000 (01:31 +0900)
14 files changed:
src/boot/bootctl.c
src/core/cgroup.c
src/delta/delta.c
src/gpt-auto-generator/gpt-auto-generator.c
src/import/import-common.c
src/import/import-fs.c
src/import/pull-common.c
src/journal/sd-journal.c
src/libsystemd/sd-device/device-private.c
src/libsystemd/sd-device/sd-device.c
src/portable/portable.c
src/shared/generator.c
src/systemctl/systemctl.c
src/sysv-generator/sysv-generator.c

index e7ba8b4ab9f8c77167924a23420933401b6234af..246b1319c433258765460601f41ae0cc1aa8a772 100644 (file)
@@ -165,13 +165,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)
@@ -754,7 +754,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;
 
@@ -763,7 +763,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;
@@ -792,12 +792,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)
@@ -838,9 +838,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);
 
@@ -870,10 +870,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);
@@ -888,7 +888,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)
@@ -933,7 +933,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;
 
index 4b16bb3367f1ecbb1ce4e7ad1080d1cdebaa4144..1ed5723892662696deb3234767b67b7833d15644 100644 (file)
@@ -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);
 
index b9100749649ad75e8d63bbbc1a4b5f2c32201201..bc11aa828a6f2f395fb9f6ec032009aa44a98451 100644 (file)
@@ -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;
index f1db2cbc469ea4f8fc763c8421e44295ecc969f7..f6e37670b90624c5b516194a15202209fb006f3c 100644 (file)
@@ -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);
index 1f63ebb7619448307b24bf31f50bbe7ee5ea514f..2f27dda76b29bf909ac1b5fce25a8c7ade9a2b00 100644 (file)
@@ -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);
index abb4efac9991c3d8f3512092a41b842a2c8576b7..f8f3a23206ff2097c4d9e7c34301d918baea5591 100644 (file)
@@ -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)
index 62b52309a4a3499b394a58c683214b6f10540e25..249ea533e63b63c474aef241c471df999be444e0 100644 (file)
@@ -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);
index a4f173161375b40d9cb8ae6d893af1d4a0afcdb0..82b180b019f2fe8c9015ed8217205a4fd6a1909f 100644 (file)
@@ -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;
index a0855001e308f1af59951d253fa7ae8e8407625b..731b0ed0a7c6cf9bed8f72db19690dc8412f1f8e 100644 (file)
@@ -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);
index 773be6ae1ef30a623bca585b983121dce685802e..d0f84178076f0a5e7a767675b4993efb6013f1ee 100644 (file)
@@ -1735,8 +1735,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;
 
@@ -1763,7 +1762,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 */
@@ -1838,7 +1837,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);
 
index 8202a8ca2e405cfc51c012a7c57a73b578d0795a..4956ae7310a5843e00286b5efa21c33285e61b0f 100644 (file)
@@ -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;
index 0a5413ce04e4d64f6cad4fbe79d802d15ca62c50..7273fde1860fb8d9072a35093ede0bbd9faf858b 100644 (file)
@@ -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");
index 31bc776449eec0b8984720beee49288296d68d6b..8b02ead39b1a518ec0e0b00a5dce6979bc0f4f48 100644 (file)
@@ -6277,8 +6277,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. */
index 13a9a77e81d55a3045f8e8a08f70f8021e50b9c2..28f8ab301b6bf8477a96dd8c3a08ae7ff7328d1d 100644 (file)
@@ -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,