diff options
author | Lennart Poettering <lennart@poettering.net> | 2019-07-11 19:14:16 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2019-07-12 14:31:12 +0900 |
commit | b910cc72c0fb56d96bf98704450fba1f339d8527 (patch) | |
tree | c36280c1d426b1ec859ecb55872314d6a9855f35 | |
parent | 6fa0524133ce54889f870d7ad17ab1d1832d7460 (diff) | |
download | systemd-b910cc72c0fb56d96bf98704450fba1f339d8527.tar.gz systemd-b910cc72c0fb56d96bf98704450fba1f339d8527.tar.bz2 systemd-b910cc72c0fb56d96bf98704450fba1f339d8527.zip |
tree-wide: get rid of strappend()
It's a special case of strjoin(), so no need to keep both. In particular
as typing strjoin() is even shoert than strappend().
68 files changed, 115 insertions, 146 deletions
diff --git a/src/activate/activate.c b/src/activate/activate.c index 8bdf2e50aa..15a3150666 100644 --- a/src/activate/activate.c +++ b/src/activate/activate.c @@ -151,7 +151,7 @@ static int exec_process(const char *name, char **argv, char **env, int start_fd, _cleanup_free_ char *p; const char *n; - p = strappend(*s, "="); + p = strjoin(*s, "="); if (!p) return log_oom(); @@ -226,7 +226,7 @@ static int exec_process(const char *name, char **argv, char **env, int start_fd, if (!names) return log_oom(); - e = strappend("LISTEN_FDNAMES=", names); + e = strjoin("LISTEN_FDNAMES=", names); if (!e) return log_oom(); diff --git a/src/basic/btrfs-util.c b/src/basic/btrfs-util.c index 10ca893da0..1ee0110e2f 100644 --- a/src/basic/btrfs-util.c +++ b/src/basic/btrfs-util.c @@ -1517,12 +1517,7 @@ static int subvol_snapshot_children( if (ioctl(old_fd, BTRFS_IOC_INO_LOOKUP, &ino_args) < 0) return -errno; - /* The kernel returns an empty name if the - * subvolume is in the top-level directory, - * and otherwise appends a slash, so that we - * can just concatenate easily here, without - * adding a slash. */ - c = strappend(ino_args.name, p); + c = path_join(ino_args.name, p); if (!c) return -ENOMEM; diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index 446f63023b..7d610475a8 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -1922,7 +1922,7 @@ char *cg_escape(const char *p) { } if (need_prefix) - return strappend("_", p); + return strjoin("_", p); return strdup(p); } diff --git a/src/basic/env-util.c b/src/basic/env-util.c index b39b1ed0f8..a6503cf2b6 100644 --- a/src/basic/env-util.c +++ b/src/basic/env-util.c @@ -567,7 +567,7 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) { t = strv_env_get_n(env, word+2, e-word-2, flags); - k = strappend(r, t); + k = strjoin(r, t); if (!k) return NULL; @@ -623,7 +623,7 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) { else if (!t && state == DEFAULT_VALUE) t = v = replace_env_n(test_value, e-test_value, env, flags); - k = strappend(r, t); + k = strjoin(r, t); if (!k) return NULL; @@ -642,7 +642,7 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) { t = strv_env_get_n(env, word+1, e-word-1, flags); - k = strappend(r, t); + k = strjoin(r, t); if (!k) return NULL; @@ -661,7 +661,7 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) { assert(flags & REPLACE_ENV_ALLOW_BRACELESS); t = strv_env_get_n(env, word+1, e-word-1, flags); - return strappend(r, t); + return strjoin(r, t); } else return strnappend(r, word, e-word); } diff --git a/src/basic/io-util.c b/src/basic/io-util.c index d19c78c2ca..4acd17df84 100644 --- a/src/basic/io-util.c +++ b/src/basic/io-util.c @@ -257,7 +257,7 @@ ssize_t sparse_write(int fd, const void *p, size_t sz, size_t run_length) { char* set_iovec_string_field(struct iovec *iovec, size_t *n_iovec, const char *field, const char *value) { char *x; - x = strappend(field, value); + x = strjoin(field, value); if (x) iovec[(*n_iovec)++] = IOVEC_MAKE_STRING(x); return x; @@ -312,7 +312,7 @@ int iovw_put_string_field(struct iovec_wrapper *iovw, const char *field, const c _cleanup_free_ char *x = NULL; int r; - x = strappend(field, value); + x = strjoin(field, value); if (!x) return log_oom(); diff --git a/src/basic/memfd-util.c b/src/basic/memfd-util.c index f88f0fc80c..a382b0494a 100644 --- a/src/basic/memfd-util.c +++ b/src/basic/memfd-util.c @@ -41,7 +41,7 @@ int memfd_new(const char *name) { if (!e) return -ENOMEM; - g = strappend("sd-", e); + g = strjoin("sd-", e); if (!g) return -ENOMEM; diff --git a/src/basic/string-util.c b/src/basic/string-util.c index 474903b2a8..7c487fb9a3 100644 --- a/src/basic/string-util.c +++ b/src/basic/string-util.c @@ -206,10 +206,6 @@ char *strnappend(const char *s, const char *suffix, size_t b) { return r; } -char *strappend(const char *s, const char *suffix) { - return strnappend(s, suffix, strlen_ptr(suffix)); -} - char *strjoin_real(const char *x, ...) { va_list ap; size_t l; diff --git a/src/basic/string-util.h b/src/basic/string-util.h index ef136da49e..76767afcac 100644 --- a/src/basic/string-util.h +++ b/src/basic/string-util.h @@ -108,7 +108,6 @@ const char* split(const char **state, size_t *l, const char *separator, SplitFla #define _FOREACH_WORD(word, length, s, separator, flags, state) \ for ((state) = (s), (word) = split(&(state), &(length), (separator), (flags)); (word); (word) = split(&(state), &(length), (separator), (flags))) -char *strappend(const char *s, const char *suffix); char *strnappend(const char *s, const char *suffix, size_t length); char *strjoin_real(const char *x, ...) _sentinel_; diff --git a/src/basic/strv.c b/src/basic/strv.c index 0a1adbf30b..2ae685f35a 100644 --- a/src/basic/strv.c +++ b/src/basic/strv.c @@ -233,7 +233,7 @@ int strv_extend_strv_concat(char ***a, char **b, const char *suffix) { STRV_FOREACH(s, b) { char *v; - v = strappend(*s, suffix); + v = strjoin(*s, suffix); if (!v) return -ENOMEM; diff --git a/src/basic/unit-def.c b/src/basic/unit-def.c index 0544fee9ec..70985ddecb 100644 --- a/src/basic/unit-def.c +++ b/src/basic/unit-def.c @@ -15,7 +15,7 @@ char *unit_dbus_path_from_name(const char *name) { if (!e) return NULL; - return strappend("/org/freedesktop/systemd1/unit/", e); + return strjoin("/org/freedesktop/systemd1/unit/", e); } int unit_name_from_dbus_path(const char *path, char **name) { diff --git a/src/basic/unit-name.c b/src/basic/unit-name.c index 1b81fe268f..af873d0ffd 100644 --- a/src/basic/unit-name.c +++ b/src/basic/unit-name.c @@ -402,7 +402,7 @@ int unit_name_path_escape(const char *f, char **ret) { } int unit_name_path_unescape(const char *f, char **ret) { - char *s; + _cleanup_free_ char *s = NULL; int r; assert(f); @@ -415,34 +415,27 @@ int unit_name_path_unescape(const char *f, char **ret) { if (!s) return -ENOMEM; } else { - char *w; + _cleanup_free_ char *w = NULL; r = unit_name_unescape(f, &w); if (r < 0) return r; /* Don't accept trailing or leading slashes */ - if (startswith(w, "/") || endswith(w, "/")) { - free(w); + if (startswith(w, "/") || endswith(w, "/")) return -EINVAL; - } /* Prefix a slash again */ - s = strappend("/", w); - free(w); + s = strjoin("/", w); if (!s) return -ENOMEM; - if (!path_is_normalized(s)) { - free(s); + if (!path_is_normalized(s)) return -EINVAL; - } } if (ret) - *ret = s; - else - free(s); + *ret = TAKE_PTR(s); return 0; } @@ -519,7 +512,7 @@ int unit_name_from_path(const char *path, const char *suffix, char **ret) { if (r < 0) return r; - s = strappend(p, suffix); + s = strjoin(p, suffix); if (!s) return -ENOMEM; @@ -719,7 +712,7 @@ int slice_build_subslice(const char *slice, const char *name, char **ret) { return -EINVAL; if (streq(slice, SPECIAL_ROOT_SLICE)) - subslice = strappend(name, ".slice"); + subslice = strjoin(name, ".slice"); else { char *e; diff --git a/src/binfmt/binfmt.c b/src/binfmt/binfmt.c index dda979cc42..aa9d811f2e 100644 --- a/src/binfmt/binfmt.c +++ b/src/binfmt/binfmt.c @@ -44,7 +44,7 @@ static int delete_rule(const char *rule) { return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Rule file name '%s' is not valid, refusing.", x + 1); - fn = strappend("/proc/sys/fs/binfmt_misc/", x+1); + fn = path_join("/proc/sys/fs/binfmt_misc", x+1); if (!fn) return log_oom(); diff --git a/src/core/execute.c b/src/core/execute.c index d8137090ed..9c086103ae 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -1700,7 +1700,7 @@ static int build_environment( } if (home) { - x = strappend("HOME=", home); + x = strjoin("HOME=", home); if (!x) return -ENOMEM; @@ -1709,19 +1709,19 @@ static int build_environment( } if (username) { - x = strappend("LOGNAME=", username); + x = strjoin("LOGNAME=", username); if (!x) return -ENOMEM; our_env[n_env++] = x; - x = strappend("USER=", username); + x = strjoin("USER=", username); if (!x) return -ENOMEM; our_env[n_env++] = x; } if (shell) { - x = strappend("SHELL=", shell); + x = strjoin("SHELL=", shell); if (!x) return -ENOMEM; @@ -1750,7 +1750,7 @@ static int build_environment( if (!term) term = default_term_for_tty(tty_path); - x = strappend("TERM=", term); + x = strjoin("TERM=", term); if (!x) return -ENOMEM; our_env[n_env++] = x; diff --git a/src/core/manager.c b/src/core/manager.c index 09507648fb..3d3c3b0cba 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -893,7 +893,7 @@ static int manager_setup_notify(Manager *m) { fd_inc_rcvbuf(fd, NOTIFY_RCVBUF_SIZE); - m->notify_socket = strappend(m->prefix[EXEC_DIRECTORY_RUNTIME], "/systemd/notify"); + m->notify_socket = path_join(m->prefix[EXEC_DIRECTORY_RUNTIME], "systemd/notify"); if (!m->notify_socket) return log_oom(); diff --git a/src/core/mount-setup.c b/src/core/mount-setup.c index b97285e556..ea7b0a80cb 100644 --- a/src/core/mount-setup.c +++ b/src/core/mount-setup.c @@ -332,7 +332,7 @@ int mount_cgroup_controllers(void) { if (!options) options = TAKE_PTR(controller); - where = strappend("/sys/fs/cgroup/", options); + where = path_join("/sys/fs/cgroup", options); if (!where) return log_oom(); diff --git a/src/core/service.c b/src/core/service.c index 30687a967a..f72d6d9cbe 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -1532,7 +1532,7 @@ static int service_spawn( if (r < 0) return r; - t = strappend("REMOTE_ADDR=", addr); + t = strjoin("REMOTE_ADDR=", addr); if (!t) return -ENOMEM; our_env[n_env++] = t; diff --git a/src/core/timer.c b/src/core/timer.c index fa0af4c3a2..7d816856b1 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -146,7 +146,7 @@ static int timer_setup_persistent(Timer *t) { if (r < 0) return r; - t->stamp_path = strappend("/var/lib/systemd/timers/stamp-", UNIT(t)->id); + t->stamp_path = strjoin("/var/lib/systemd/timers/stamp-", UNIT(t)->id); } else { const char *e; diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c index 6308cda610..f81ae3b788 100644 --- a/src/coredump/coredump.c +++ b/src/coredump/coredump.c @@ -396,7 +396,7 @@ static int save_external_coredump( _cleanup_free_ char *fn_compressed = NULL, *tmp_compressed = NULL; _cleanup_close_ int fd_compressed = -1; - fn_compressed = strappend(fn, COMPRESSED_EXT); + fn_compressed = strjoin(fn, COMPRESSED_EXT); if (!fn_compressed) { log_oom(); goto uncompressed; diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c index 92314b667e..127b3c5380 100644 --- a/src/cryptsetup/cryptsetup-generator.c +++ b/src/cryptsetup/cryptsetup-generator.c @@ -583,12 +583,12 @@ static int add_proc_cmdline_devices(void) { continue; if (!d->name) { - d->name = strappend("luks-", d->uuid); + d->name = strjoin("luks-", d->uuid); if (!d->name) return log_oom(); } - device = strappend("UUID=", d->uuid); + device = strjoin("UUID=", d->uuid); if (!device) return log_oom(); diff --git a/src/debug-generator/debug-generator.c b/src/debug-generator/debug-generator.c index 09220dc98c..e73dde32b8 100644 --- a/src/debug-generator/debug-generator.c +++ b/src/debug-generator/debug-generator.c @@ -131,7 +131,7 @@ static int generate_wants_symlinks(void) { if (!p) return log_oom(); - f = strappend(SYSTEM_DATA_UNIT_PATH "/", *u); + f = path_join(SYSTEM_DATA_UNIT_PATH, *u); if (!f) return log_oom(); diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c index f6e37670b9..49149b59be 100644 --- a/src/gpt-auto-generator/gpt-auto-generator.c +++ b/src/gpt-auto-generator/gpt-auto-generator.c @@ -132,7 +132,7 @@ static int add_cryptsetup(const char *id, const char *what, bool rw, bool requir if (device) { char *ret; - ret = strappend("/dev/mapper/", id); + ret = path_join("/dev/mapper", id); if (!ret) return log_oom(); diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index c35ef55662..75cba5827c 100644 --- a/src/hostname/hostnamed.c +++ b/src/hostname/hostnamed.c @@ -253,11 +253,11 @@ static char* context_fallback_icon_name(Context *c) { assert(c); if (!isempty(c->data[PROP_CHASSIS])) - return strappend("computer-", c->data[PROP_CHASSIS]); + return strjoin("computer-", c->data[PROP_CHASSIS]); chassis = fallback_chassis(); if (chassis) - return strappend("computer-", chassis); + return strjoin("computer-", chassis); return strdup("computer"); } diff --git a/src/import/pull-job.c b/src/import/pull-job.c index 881bba0eeb..4561794548 100644 --- a/src/import/pull-job.c +++ b/src/import/pull-job.c @@ -584,7 +584,7 @@ int pull_job_begin(PullJob *j) { if (!cc) return -ENOMEM; - hdr = strappend("If-None-Match: ", cc); + hdr = strjoin("If-None-Match: ", cc); if (!hdr) return -ENOMEM; diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 3e1ca5b1ba..764b3c217e 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -1101,19 +1101,19 @@ static int add_matches(sd_journal *j, char **args) { if (!comm) return log_oom(); - t = strappend("_COMM=", comm); + t = strjoin("_COMM=", comm); if (!t) return log_oom(); /* Append _EXE only if the interpreter is not a link. Otherwise, it might be outdated often. */ if (lstat(interpreter, &st) == 0 && !S_ISLNK(st.st_mode)) { - t2 = strappend("_EXE=", interpreter); + t2 = strjoin("_EXE=", interpreter); if (!t2) return log_oom(); } } else { - t = strappend("_EXE=", p); + t = strjoin("_EXE=", p); if (!t) return log_oom(); } diff --git a/src/journal/journald-kmsg.c b/src/journal/journald-kmsg.c index ce82102eed..366298758c 100644 --- a/src/journal/journald-kmsg.c +++ b/src/journal/journald-kmsg.c @@ -217,7 +217,7 @@ void dev_kmsg_record(Server *s, char *p, size_t l) { char *b; if (sd_device_get_devname(d, &g) >= 0) { - b = strappend("_UDEV_DEVNODE=", g); + b = strjoin("_UDEV_DEVNODE=", g); if (b) { iovec[n++] = IOVEC_MAKE_STRING(b); z++; @@ -225,7 +225,7 @@ void dev_kmsg_record(Server *s, char *p, size_t l) { } if (sd_device_get_sysname(d, &g) >= 0) { - b = strappend("_UDEV_SYSNAME=", g); + b = strjoin("_UDEV_SYSNAME=", g); if (b) { iovec[n++] = IOVEC_MAKE_STRING(b); z++; @@ -238,7 +238,7 @@ void dev_kmsg_record(Server *s, char *p, size_t l) { if (j >= N_IOVEC_UDEV_FIELDS) break; - b = strappend("_UDEV_DEVLINK=", g); + b = strjoin("_UDEV_DEVLINK=", g); if (b) { iovec[n++] = IOVEC_MAKE_STRING(b); z++; @@ -271,13 +271,13 @@ void dev_kmsg_record(Server *s, char *p, size_t l) { goto finish; if (identifier) { - syslog_identifier = strappend("SYSLOG_IDENTIFIER=", identifier); + syslog_identifier = strjoin("SYSLOG_IDENTIFIER=", identifier); if (syslog_identifier) iovec[n++] = IOVEC_MAKE_STRING(syslog_identifier); } if (pid) { - syslog_pid = strappend("SYSLOG_PID=", pid); + syslog_pid = strjoin("SYSLOG_PID=", pid); if (syslog_pid) iovec[n++] = IOVEC_MAKE_STRING(syslog_pid); } diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index ce0d9ce8c9..a0c2dcd2d0 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -737,7 +737,7 @@ static void server_cache_hostname(Server *s) { if (!t) return; - x = strappend("_HOSTNAME=", t); + x = strjoin("_HOSTNAME=", t); if (!x) return; diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c index 24d4ac30b2..afebadeccc 100644 --- a/src/journal/journald-stream.c +++ b/src/journal/journald-stream.c @@ -294,7 +294,7 @@ static int stdout_stream_log(StdoutStream *s, const char *p, LineBreak line_brea } if (s->identifier) { - syslog_identifier = strappend("SYSLOG_IDENTIFIER=", s->identifier); + syslog_identifier = strjoin("SYSLOG_IDENTIFIER=", s->identifier); if (syslog_identifier) iovec[n++] = IOVEC_MAKE_STRING(syslog_identifier); } @@ -311,7 +311,7 @@ static int stdout_stream_log(StdoutStream *s, const char *p, LineBreak line_brea iovec[n++] = IOVEC_MAKE_STRING(c); } - message = strappend("MESSAGE=", p); + message = strjoin("MESSAGE=", p); if (message) iovec[n++] = IOVEC_MAKE_STRING(message); @@ -649,7 +649,7 @@ static int stdout_stream_load(StdoutStream *stream, const char *fname) { assert(fname); if (!stream->state_file) { - stream->state_file = strappend("/run/systemd/journal/streams/", fname); + stream->state_file = path_join("/run/systemd/journal/streams", fname); if (!stream->state_file) return log_oom(); } diff --git a/src/journal/test-journal-flush.c b/src/journal/test-journal-flush.c index de9d23a003..50500222ad 100644 --- a/src/journal/test-journal-flush.c +++ b/src/journal/test-journal-flush.c @@ -10,6 +10,7 @@ #include "journal-file.h" #include "journal-internal.h" #include "macro.h" +#include "path-util.h" #include "string-util.h" int main(int argc, char *argv[]) { @@ -23,7 +24,7 @@ int main(int argc, char *argv[]) { assert_se(mkdtemp(dn)); (void) chattr_path(dn, FS_NOCOW_FL, FS_NOCOW_FL, NULL); - fn = strappend(dn, "/test.journal"); + fn = path_join(dn, "test.journal"); r = journal_file_open(-1, fn, O_CREAT|O_RDWR, 0644, false, 0, false, NULL, NULL, NULL, NULL, &new_journal); assert_se(r >= 0); diff --git a/src/libsystemd/sd-bus/bus-error.c b/src/libsystemd/sd-bus/bus-error.c index 386187412b..ac1a954546 100644 --- a/src/libsystemd/sd-bus/bus-error.c +++ b/src/libsystemd/sd-bus/bus-error.c @@ -180,7 +180,7 @@ static int errno_to_bus_error_name_new(int error, char **ret) { if (!name) return 0; - n = strappend("System.Error.", name); + n = strjoin("System.Error.", name); if (!n) return -ENOMEM; diff --git a/src/libsystemd/sd-login/sd-login.c b/src/libsystemd/sd-login/sd-login.c index 0dc368e6e2..ef22e190e4 100644 --- a/src/libsystemd/sd-login/sd-login.c +++ b/src/libsystemd/sd-login/sd-login.c @@ -314,7 +314,7 @@ static int file_of_seat(const char *seat, char **_p) { if (!filename_is_valid(seat)) return -EINVAL; - p = strappend("/run/systemd/seats/", seat); + p = path_join("/run/systemd/seats", seat); } else { _cleanup_free_ char *buf = NULL; @@ -322,9 +322,8 @@ static int file_of_seat(const char *seat, char **_p) { if (r < 0) return r; - p = strappend("/run/systemd/seats/", buf); + p = path_join("/run/systemd/seats", buf); } - if (!p) return -ENOMEM; @@ -427,7 +426,7 @@ static int file_of_session(const char *session, char **_p) { if (!session_id_valid(session)) return -EINVAL; - p = strappend("/run/systemd/sessions/", session); + p = path_join("/run/systemd/sessions", session); } else { _cleanup_free_ char *buf = NULL; @@ -435,7 +434,7 @@ static int file_of_session(const char *session, char **_p) { if (r < 0) return r; - p = strappend("/run/systemd/sessions/", buf); + p = path_join("/run/systemd/sessions", buf); } if (!p) diff --git a/src/libsystemd/sd-path/sd-path.c b/src/libsystemd/sd-path/sd-path.c index 2dfde4ca71..ad56ddb580 100644 --- a/src/libsystemd/sd-path/sd-path.c +++ b/src/libsystemd/sd-path/sd-path.c @@ -83,7 +83,7 @@ static int from_user_dir(const char *field, char **buffer, const char **ret) { if (r < 0) return r; - fn = strappend(c, "/user-dirs.dirs"); + fn = path_join(c, "user-dirs.dirs"); if (!fn) return -ENOMEM; @@ -141,7 +141,7 @@ static int from_user_dir(const char *field, char **buffer, const char **ret) { if (r < 0) return r; - cc = strappend(h, p+5); + cc = path_join(h, p+5); if (!cc) return -ENOMEM; @@ -179,7 +179,7 @@ fallback: if (r < 0) return r; - cc = strappend(h, "/Desktop"); + cc = path_join(h, "Desktop"); if (!cc) return -ENOMEM; diff --git a/src/locale/keymap-util.c b/src/locale/keymap-util.c index 1394514839..f8c36c94f5 100644 --- a/src/locale/keymap-util.c +++ b/src/locale/keymap-util.c @@ -353,7 +353,7 @@ int vconsole_write_data(Context *c) { _cleanup_free_ char *s = NULL; char **u; - s = strappend("KEYMAP=", c->vc_keymap); + s = strjoin("KEYMAP=", c->vc_keymap); if (!s) return -ENOMEM; @@ -370,7 +370,7 @@ int vconsole_write_data(Context *c) { _cleanup_free_ char *s = NULL; char **u; - s = strappend("KEYMAP_TOGGLE=", c->vc_keymap_toggle); + s = strjoin("KEYMAP_TOGGLE=", c->vc_keymap_toggle); if (!s) return -ENOMEM; diff --git a/src/login/logind-acl.c b/src/login/logind-acl.c index d2f4e60f98..2e13e4aed6 100644 --- a/src/login/logind-acl.c +++ b/src/login/logind-acl.c @@ -222,7 +222,7 @@ int devnode_acl_all(const char *seat, if (cunescape(dent->d_name, UNESCAPE_RELAX, &unescaped_devname) < 0) return -ENOMEM; - n = strappend("/dev/", unescaped_devname); + n = path_join("/dev", unescaped_devname); if (!n) return -ENOMEM; diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 1f5bdfecfc..b7c6e00e95 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -1322,7 +1322,7 @@ static int trigger_device(Manager *m, sd_device *d) { if (r < 0) return r; - t = strappend(p, "/uevent"); + t = path_join(p, "uevent"); if (!t) return -ENOMEM; diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index d963706dce..d32e299101 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -17,6 +17,7 @@ #include "logind-inhibit.h" #include "mkdir.h" #include "parse-util.h" +#include "path-util.h" #include "string-table.h" #include "string-util.h" #include "tmpfile-util.h" @@ -32,7 +33,7 @@ Inhibitor* inhibitor_new(Manager *m, const char* id) { if (!i) return NULL; - i->state_file = strappend("/run/systemd/inhibit/", id); + i->state_file = path_join("/run/systemd/inhibit", id); if (!i->state_file) return mfree(i); diff --git a/src/login/logind-seat-dbus.c b/src/login/logind-seat-dbus.c index c33a0e0ad4..3c58929611 100644 --- a/src/login/logind-seat-dbus.c +++ b/src/login/logind-seat-dbus.c @@ -304,7 +304,7 @@ char *seat_bus_path(Seat *s) { if (!t) return NULL; - return strappend("/org/freedesktop/login1/seat/", t); + return strjoin("/org/freedesktop/login1/seat/", t); } int seat_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) { diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c index c3ad5f9b5b..9577ff86f4 100644 --- a/src/login/logind-seat.c +++ b/src/login/logind-seat.c @@ -19,6 +19,7 @@ #include "logind-session-dbus.h" #include "mkdir.h" #include "parse-util.h" +#include "path-util.h" #include "stdio-util.h" #include "string-util.h" #include "terminal-util.h" @@ -44,7 +45,7 @@ int seat_new(Seat** ret, Manager *m, const char *id) { .manager = m, }; - s->state_file = strappend("/run/systemd/seats/", id); + s->state_file = path_join("/run/systemd/seats", id); if (!s->state_file) return -ENOMEM; diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c index c297f62cdf..fc194a3e72 100644 --- a/src/login/logind-session-dbus.c +++ b/src/login/logind-session-dbus.c @@ -634,7 +634,7 @@ char *session_bus_path(Session *s) { if (!t) return NULL; - return strappend("/org/freedesktop/login1/session/", t); + return strjoin("/org/freedesktop/login1/session/", t); } int session_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) { diff --git a/src/login/logind-session.c b/src/login/logind-session.c index 17700c6921..f78453736d 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -67,7 +67,7 @@ int session_new(Session **ret, Manager *m, const char *id) { .tty_validity = _TTY_VALIDITY_INVALID, }; - s->state_file = strappend("/run/systemd/sessions/", id); + s->state_file = path_join("/run/systemd/sessions", id); if (!s->state_file) return -ENOMEM; @@ -899,7 +899,7 @@ static int get_tty_atime(const char *tty, usec_t *atime) { assert(atime); if (!path_is_absolute(tty)) { - p = strappend("/dev/", tty); + p = path_join("/dev", tty); if (!p) return -ENOMEM; diff --git a/src/login/sysfs-show.c b/src/login/sysfs-show.c index a41d83b897..9104e023e8 100644 --- a/src/login/sysfs-show.c +++ b/src/login/sysfs-show.c @@ -109,7 +109,7 @@ static int show_sysfs_one( if (++(*i_dev) < n_dev) { _cleanup_free_ char *p = NULL; - p = strappend(prefix, lookahead < n_dev ? special_glyph(SPECIAL_GLYPH_TREE_VERTICAL) : " "); + p = strjoin(prefix, lookahead < n_dev ? special_glyph(SPECIAL_GLYPH_TREE_VERTICAL) : " "); if (!p) return -ENOMEM; diff --git a/src/machine/image-dbus.c b/src/machine/image-dbus.c index 7e7f0d51bf..b45355d86f 100644 --- a/src/machine/image-dbus.c +++ b/src/machine/image-dbus.c @@ -458,7 +458,7 @@ char *image_bus_path(const char *name) { if (!e) return NULL; - return strappend("/org/freedesktop/machine1/image/", e); + return strjoin("/org/freedesktop/machine1/image/", e); } int image_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) { diff --git a/src/machine/machine-dbus.c b/src/machine/machine-dbus.c index b89e6046d9..0d58b5eb8b 100644 --- a/src/machine/machine-dbus.c +++ b/src/machine/machine-dbus.c @@ -1383,7 +1383,7 @@ char *machine_bus_path(Machine *m) { if (!e) return NULL; - return strappend("/org/freedesktop/machine1/machine/", e); + return strjoin("/org/freedesktop/machine1/machine/", e); } int machine_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) { diff --git a/src/machine/machine.c b/src/machine/machine.c index b203a1dde8..4d07a7893a 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -22,6 +22,7 @@ #include "machine.h" #include "mkdir.h" #include "parse-util.h" +#include "path-util.h" #include "process-util.h" #include "serialize.h" #include "special.h" @@ -53,7 +54,7 @@ Machine* machine_new(Manager *manager, MachineClass class, const char *name) { goto fail; if (class != MACHINE_HOST) { - m->state_file = strappend("/run/systemd/machines/", m->name); + m->state_file = path_join("/run/systemd/machines", m->name); if (!m->state_file) goto fail; } diff --git a/src/notify/notify.c b/src/notify/notify.c index 750529bbbd..c2e7683bcf 100644 --- a/src/notify/notify.c +++ b/src/notify/notify.c @@ -166,7 +166,7 @@ static int run(int argc, char* argv[]) { our_env[i++] = (char*) "READY=1"; if (arg_status) { - status = strappend("STATUS=", arg_status); + status = strjoin("STATUS=", arg_status); if (!status) return log_oom(); diff --git a/src/nspawn/nspawn-network.c b/src/nspawn/nspawn-network.c index d09e12346f..214cf5749b 100644 --- a/src/nspawn/nspawn-network.c +++ b/src/nspawn/nspawn-network.c @@ -489,7 +489,7 @@ int setup_macvlan(const char *machine_name, pid_t pid, char **ifaces) { if (r < 0) return log_error_errno(r, "Failed to add netlink interface index: %m"); - n = strappend("mv-", *i); + n = strjoin("mv-", *i); if (!n) return log_oom(); @@ -564,7 +564,7 @@ int setup_ipvlan(const char *machine_name, pid_t pid, char **ifaces) { if (r < 0) return log_error_errno(r, "Failed to add netlink interface index: %m"); - n = strappend("iv-", *i); + n = strjoin("iv-", *i); if (!n) return log_oom(); diff --git a/src/nspawn/nspawn-settings.c b/src/nspawn/nspawn-settings.c index 9ff37c6dbd..3a99736813 100644 --- a/src/nspawn/nspawn-settings.c +++ b/src/nspawn/nspawn-settings.c @@ -505,7 +505,7 @@ int config_parse_network_zone( assert(lvalue); assert(rvalue); - j = strappend("vz-", rvalue); + j = strjoin("vz-", rvalue); if (!ifname_valid(j)) { log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid network zone name, ignoring: %s", rvalue); return 0; diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index a563c026dd..117a637699 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -725,7 +725,7 @@ static int parse_argv(int argc, char *argv[]) { case ARG_NETWORK_ZONE: { char *j; - j = strappend("vz-", optarg); + j = strjoin("vz-", optarg); if (!j) return log_oom(); diff --git a/src/resolve/resolvectl.c b/src/resolve/resolvectl.c index 94ec8be896..f44d0b8343 100644 --- a/src/resolve/resolvectl.c +++ b/src/resolve/resolvectl.c @@ -1281,7 +1281,7 @@ static int read_domain_one(sd_bus_message *m, bool with_ifindex, char **ret) { } if (route_only) - str = strappend("~", domain); + str = strjoin("~", domain); else str = strdup(domain); if (!str) diff --git a/src/resolve/resolved-dns-answer.c b/src/resolve/resolved-dns-answer.c index 0ee7340ffc..e5693bf72d 100644 --- a/src/resolve/resolved-dns-answer.c +++ b/src/resolve/resolved-dns-answer.c @@ -161,7 +161,7 @@ int dns_answer_add_soa(DnsAnswer *a, const char *name, uint32_t ttl, int ifindex if (!soa->soa.mname) return -ENOMEM; - soa->soa.rname = strappend("root.", name); + soa->soa.rname = strjoin("root.", name); if (!soa->soa.rname) return -ENOMEM; diff --git a/src/resolve/resolved-dns-dnssec.c b/src/resolve/resolved-dns-dnssec.c index 997cb986e6..fc375a8821 100644 --- a/src/resolve/resolved-dns-dnssec.c +++ b/src/resolve/resolved-dns-dnssec.c @@ -2182,7 +2182,7 @@ static int dnssec_test_positive_wildcard_nsec( return -EBADMSG; /* Replace the label we stripped off with an asterisk */ - wc = strappend("*.", name); + wc = strjoin("*.", name); if (!wc) return -ENOMEM; diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c index 02153b929f..d65c780791 100644 --- a/src/resolve/resolved-manager.c +++ b/src/resolve/resolved-manager.c @@ -1500,7 +1500,7 @@ void manager_cleanup_saved_user(Manager *m) { continue; rm: - p = strappend("/run/systemd/resolve/netif/", de->d_name); + p = path_join("/run/systemd/resolve/netif", de->d_name); if (!p) { log_oom(); return; diff --git a/src/shared/bus-unit-procs.c b/src/shared/bus-unit-procs.c index 23c5a12454..aeba2ebfd3 100644 --- a/src/shared/bus-unit-procs.c +++ b/src/shared/bus-unit-procs.c @@ -241,7 +241,7 @@ static int dump_processes( special = special_glyph(more ? SPECIAL_GLYPH_TREE_VERTICAL : SPECIAL_GLYPH_TREE_SPACE); - pp = strappend(prefix, special); + pp = strjoin(prefix, special); if (!pp) return -ENOMEM; diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index 6a7358e301..b1945ceb8d 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -313,7 +313,7 @@ static int bus_append_exec_command(sd_bus_message *m, const char *field, const c if (!is_ex_prop && (flags & (EXEC_COMMAND_NO_ENV_EXPAND|EXEC_COMMAND_FULLY_PRIVILEGED|EXEC_COMMAND_NO_SETUID|EXEC_COMMAND_AMBIENT_MAGIC))) { /* Upgrade the ExecXYZ= property to ExecXYZEx= for convenience */ is_ex_prop = true; - upgraded_name = strappend(field, "Ex"); + upgraded_name = strjoin(field, "Ex"); if (!upgraded_name) return log_oom(); } diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index b3b05872e9..8e301250bc 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -990,7 +990,7 @@ int bus_message_print_all_properties( return log_oom(); } - name_with_equal = strappend(name, "="); + name_with_equal = strjoin(name, "="); if (!name_with_equal) return log_oom(); diff --git a/src/shared/cgroup-show.c b/src/shared/cgroup-show.c index 465e38c4fb..732bc752af 100644 --- a/src/shared/cgroup-show.c +++ b/src/shared/cgroup-show.c @@ -165,7 +165,7 @@ int show_cgroup_by_path( printf("%s%s%s\n", prefix, special_glyph(SPECIAL_GLYPH_TREE_BRANCH), cg_unescape(basename(last))); if (!p1) { - p1 = strappend(prefix, special_glyph(SPECIAL_GLYPH_TREE_VERTICAL)); + p1 = strjoin(prefix, special_glyph(SPECIAL_GLYPH_TREE_VERTICAL)); if (!p1) return -ENOMEM; } @@ -187,7 +187,7 @@ int show_cgroup_by_path( printf("%s%s%s\n", prefix, special_glyph(SPECIAL_GLYPH_TREE_RIGHT), cg_unescape(basename(last))); if (!p2) { - p2 = strappend(prefix, " "); + p2 = strjoin(prefix, " "); if (!p2) return -ENOMEM; } diff --git a/src/shared/install.c b/src/shared/install.c index 105412bc8f..68ffd12f03 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -2308,7 +2308,7 @@ int unit_file_revert( has_vendor = true; } - dropin = strappend(path, ".d"); + dropin = strjoin(path, ".d"); if (!dropin) return -ENOMEM; diff --git a/src/shared/machine-image.c b/src/shared/machine-image.c index ee086e35b4..07744b34b4 100644 --- a/src/shared/machine-image.c +++ b/src/shared/machine-image.c @@ -87,8 +87,8 @@ static char **image_settings_path(Image *image) { fn = strjoina(image->name, ".nspawn"); - FOREACH_STRING(s, "/etc/systemd/nspawn/", "/run/systemd/nspawn/") { - l[i] = strappend(s, fn); + FOREACH_STRING(s, "/etc/systemd/nspawn", "/run/systemd/nspawn") { + l[i] = path_join(s, fn); if (!l[i]) return NULL; @@ -441,7 +441,7 @@ int image_find(ImageClass class, const char *name, Image **ret) { if (errno != ENOENT) return -errno; - raw = strappend(name, ".raw"); + raw = strjoin(name, ".raw"); if (!raw) return -ENOMEM; diff --git a/src/shared/path-lookup.c b/src/shared/path-lookup.c index 6494210ee9..f1caddb477 100644 --- a/src/shared/path-lookup.c +++ b/src/shared/path-lookup.c @@ -32,7 +32,7 @@ int xdg_user_runtime_dir(char **ret, const char *suffix) { if (!e) return -ENXIO; - j = strappend(e, suffix); + j = strjoin(e, suffix); if (!j) return -ENOMEM; @@ -49,7 +49,7 @@ int xdg_user_config_dir(char **ret, const char *suffix) { e = getenv("XDG_CONFIG_HOME"); if (e) - j = strappend(e, suffix); + j = strjoin(e, suffix); else { _cleanup_free_ char *home = NULL; @@ -81,7 +81,7 @@ int xdg_user_data_dir(char **ret, const char *suffix) { e = getenv("XDG_DATA_HOME"); if (e) - j = strappend(e, suffix); + j = strjoin(e, suffix); else { _cleanup_free_ char *home = NULL; @@ -270,15 +270,15 @@ static int acquire_generator_dirs( prefix = strjoina(e, "/systemd"); } - x = strappend(prefix, "/generator"); + x = path_join(prefix, "generator"); if (!x) return -ENOMEM; - y = strappend(prefix, "/generator.early"); + y = path_join(prefix, "generator.early"); if (!y) return -ENOMEM; - z = strappend(prefix, "/generator.late"); + z = path_join(prefix, "generator.late"); if (!z) return -ENOMEM; diff --git a/src/sysctl/sysctl.c b/src/sysctl/sysctl.c index bb2643a480..9838701a3d 100644 --- a/src/sysctl/sysctl.c +++ b/src/sysctl/sysctl.c @@ -236,7 +236,7 @@ static int parse_argv(int argc, char *argv[]) { if (path_startswith(optarg, "/proc/sys")) p = strdup(optarg); else - p = strappend("/proc/sys/", optarg); + p = path_join("/proc/sys", optarg); if (!p) return log_oom(); diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 7b39f5d95b..6490fe6f0d 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -6459,7 +6459,7 @@ static int enable_sysv_units(const char *verb, char **args) { } if (!isempty(arg_root)) { - q = strappend("--root=", arg_root); + q = strjoin("--root=", arg_root); if (!q) return log_oom(); diff --git a/src/sysv-generator/sysv-generator.c b/src/sysv-generator/sysv-generator.c index 175e4a2393..5df5743823 100644 --- a/src/sysv-generator/sysv-generator.c +++ b/src/sysv-generator/sysv-generator.c @@ -642,7 +642,7 @@ static int load_sysv(SysvStub *s) { if (description) { char *d; - d = strappend(s->has_lsb ? "LSB: " : "SYSV: ", description); + d = strjoin(s->has_lsb ? "LSB: " : "SYSV: ", description); if (!d) return log_oom(); diff --git a/src/test/test-conf-files.c b/src/test/test-conf-files.c index 07b681cf43..61811311f4 100644 --- a/src/test/test-conf-files.c +++ b/src/test/test-conf-files.c @@ -30,7 +30,7 @@ static void setup_test_dir(char *tmp_dir, const char *files, ...) { while (files) { _cleanup_free_ char *path; - assert_se(path = strappend(tmp_dir, files)); + assert_se(path = path_join(tmp_dir, files)); (void) mkdir_parents(path, 0755); assert_se(write_string_file(path, "foobar", WRITE_STRING_FILE_CREATE) >= 0); diff --git a/src/test/test-copy.c b/src/test/test-copy.c index 5f4bc39580..bfe6cea41c 100644 --- a/src/test/test-copy.c +++ b/src/test/test-copy.c @@ -92,7 +92,7 @@ static void test_copy_tree(void) { STRV_FOREACH(p, files) { _cleanup_free_ char *f; - assert_se(f = strappend(original_dir, *p)); + assert_se(f = path_join(original_dir, *p)); assert_se(mkdir_parents(f, 0755) >= 0); assert_se(write_string_file(f, "file", WRITE_STRING_FILE_CREATE) == 0); @@ -101,8 +101,8 @@ static void test_copy_tree(void) { STRV_FOREACH_PAIR(link, p, links) { _cleanup_free_ char *f, *l; - assert_se(f = strappend(original_dir, *p)); - assert_se(l = strappend(original_dir, *link)); + assert_se(f = path_join(original_dir, *p)); + assert_se(l = path_join(original_dir, *link)); assert_se(mkdir_parents(l, 0755) >= 0); assert_se(symlink(f, l) == 0); @@ -117,7 +117,7 @@ static void test_copy_tree(void) { _cleanup_free_ char *buf, *f; size_t sz; - assert_se(f = strappend(copy_dir, *p)); + assert_se(f = path_join(copy_dir, *p)); assert_se(access(f, F_OK) == 0); assert_se(read_full_file(f, &buf, &sz) == 0); diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c index 90a8d5f36c..413816ceb8 100644 --- a/src/test/test-path-util.c +++ b/src/test/test-path-util.c @@ -327,7 +327,7 @@ static void test_strv_resolve(void) { search_dirs = strv_new("/dir1", "/dir2", "/dir3"); assert_se(search_dirs); STRV_FOREACH(d, search_dirs) { - char *p = strappend(tmp_dir, *d); + char *p = path_join(tmp_dir, *d); assert_se(p); assert_se(strv_push(&absolute_dirs, p) == 0); } diff --git a/src/test/test-string-util.c b/src/test/test-string-util.c index d84170bc22..8ea3994366 100644 --- a/src/test/test-string-util.c +++ b/src/test/test-string-util.c @@ -250,22 +250,6 @@ static void test_strrep(void) { assert_se(streq(zero, "")); } -static void test_strappend(void) { - _cleanup_free_ char *t1, *t2, *t3, *t4; - - t1 = strappend(NULL, NULL); - assert_se(streq(t1, "")); - - t2 = strappend(NULL, "suf"); - assert_se(streq(t2, "suf")); - - t3 = strappend("pre", NULL); - assert_se(streq(t3, "pre")); - - t4 = strappend("pre", "suf"); - assert_se(streq(t4, "presuf")); -} - static void test_string_has_cc(void) { assert_se(string_has_cc("abc\1", NULL)); assert_se(string_has_cc("abc\x7f", NULL)); @@ -568,7 +552,6 @@ int main(int argc, char *argv[]) { test_strextend(); test_strextend_with_separator(); test_strrep(); - test_strappend(); test_string_has_cc(); test_ascii_strlower(); test_strshorten(); diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c index fe91854ac8..57bbefc0c1 100644 --- a/src/timedate/timedated.c +++ b/src/timedate/timedated.c @@ -227,7 +227,7 @@ static int context_write_data_timezone(Context *c) { return r; } - p = strappend("../usr/share/zoneinfo/", c->zone); + p = path_join("../usr/share/zoneinfo", c->zone); if (!p) return log_oom(); diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 90ba32ede0..3c30612af1 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -2597,7 +2597,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer, bool case CREATE_SYMLINK: if (!i.argument) { - i.argument = path_join("/usr/share/factory/", i.path); + i.argument = path_join("/usr/share/factory", i.path); if (!i.argument) return log_oom(); } @@ -2613,7 +2613,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer, bool case COPY_FILES: if (!i.argument) { - i.argument = path_join(arg_root, "/usr/share/factory/", i.path); + i.argument = path_join(arg_root, "/usr/share/factory", i.path); if (!i.argument) return log_oom(); diff --git a/src/tty-ask-password-agent/tty-ask-password-agent.c b/src/tty-ask-password-agent/tty-ask-password-agent.c index 843c302bf4..e17140ea0c 100644 --- a/src/tty-ask-password-agent/tty-ask-password-agent.c +++ b/src/tty-ask-password-agent/tty-ask-password-agent.c @@ -480,7 +480,7 @@ static int show_passwords(void) { if (!startswith(de->d_name, "ask.")) continue; - p = strappend("/run/systemd/ask-password/", de->d_name); + p = path_join("/run/systemd/ask-password", de->d_name); if (!p) return log_oom(); |