From 3c66f40262c5e2e1be916ced122a1e03107b430a Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 31 Oct 2025 21:57:37 +0900 Subject: [PATCH 1/7] strv: introduce strv_extendf_with_size() --- src/basic/strv.c | 4 ++-- src/basic/strv.h | 3 ++- src/test/test-strv.c | 13 +++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/basic/strv.c b/src/basic/strv.c index 37f4bd44f3..4f61a42114 100644 --- a/src/basic/strv.c +++ b/src/basic/strv.c @@ -906,7 +906,7 @@ void strv_print_full(char * const *l, const char *prefix) { printf("%s%s\n", strempty(prefix), *s); } -int strv_extendf(char ***l, const char *format, ...) { +int strv_extendf_with_size(char ***l, size_t *n, const char *format, ...) { va_list ap; char *x; int r; @@ -918,7 +918,7 @@ int strv_extendf(char ***l, const char *format, ...) { if (r < 0) return -ENOMEM; - return strv_consume(l, x); + return strv_consume_with_size(l, n, x); } char* startswith_strv(const char *s, char * const *l) { diff --git a/src/basic/strv.h b/src/basic/strv.h index b358ab4c2b..1133895158 100644 --- a/src/basic/strv.h +++ b/src/basic/strv.h @@ -56,7 +56,8 @@ static inline int strv_extend(char ***l, const char *value) { int strv_extend_many_internal(char ***l, const char *value, ...); #define strv_extend_many(l, ...) strv_extend_many_internal(l, __VA_ARGS__, POINTER_MAX) -int strv_extendf(char ***l, const char *format, ...) _printf_(2,3); +int strv_extendf_with_size(char ***l, size_t *n, const char *format, ...) _printf_(3,4); +#define strv_extendf(l, ...) strv_extendf_with_size(l, NULL, __VA_ARGS__) int strv_push_with_size(char ***l, size_t *n, char *value); static inline int strv_push(char ***l, char *value) { diff --git a/src/test/test-strv.c b/src/test/test-strv.c index 88505993cd..49558850d6 100644 --- a/src/test/test-strv.c +++ b/src/test/test-strv.c @@ -749,6 +749,19 @@ TEST(strv_extendf) { ASSERT_STREQ(b[0], "test3 bar foo 128"); } +TEST(strv_extendf_with_size) { + _cleanup_strv_free_ char **a = NULL; + size_t n = 0; + + ASSERT_OK(strv_extendf_with_size(&a, &n, "test2 %s %d %s", "foo", 128, "bar")); + ASSERT_OK(strv_extendf_with_size(&a, &n, "test3 %s %s %d", "bar", "foo", 128)); + + ASSERT_EQ(n, 2u); + ASSERT_EQ(strv_length(a), n); + ASSERT_STREQ(a[0], "test2 foo 128 bar"); + ASSERT_STREQ(a[1], "test3 bar foo 128"); +} + TEST(strv_foreach) { _cleanup_strv_free_ char **a; unsigned i = 0; From 69350ee3e34a7fb8f39e3963eec2bc7ae2d4bf55 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 31 Oct 2025 22:08:35 +0900 Subject: [PATCH 2/7] string-util: introduce strextendv_with_separator() --- src/basic/string-util.c | 25 +++++++++++++++++-------- src/basic/string-util.h | 1 + 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/basic/string-util.c b/src/basic/string-util.c index 425f974237..0fe72342c7 100644 --- a/src/basic/string-util.c +++ b/src/basic/string-util.c @@ -793,12 +793,11 @@ char* strip_tab_ansi(char **ibuf, size_t *_isz, size_t highlight[2]) { return *ibuf; } -char* strextend_with_separator_internal(char **x, const char *separator, ...) { +char* strextendv_with_separator(char **x, const char *separator, va_list ap) { _cleanup_free_ char *buffer = NULL; size_t f, l, l_separator; bool need_separator; char *nr, *p; - va_list ap; if (!x) x = &buffer; @@ -808,11 +807,12 @@ char* strextend_with_separator_internal(char **x, const char *separator, ...) { need_separator = !isempty(*x); l_separator = strlen_ptr(separator); - va_start(ap, separator); + va_list aq; + va_copy(aq, ap); for (const char *t;;) { size_t n; - t = va_arg(ap, const char *); + t = va_arg(aq, const char *); if (!t) break; if (t == POINTER_MAX) @@ -824,14 +824,14 @@ char* strextend_with_separator_internal(char **x, const char *separator, ...) { n += l_separator; if (n >= SIZE_MAX - l) { - va_end(ap); + va_end(aq); return NULL; } l += n; need_separator = true; } - va_end(ap); + va_end(aq); need_separator = !isempty(*x); @@ -842,7 +842,6 @@ char* strextend_with_separator_internal(char **x, const char *separator, ...) { *x = nr; p = nr + f; - va_start(ap, separator); for (;;) { const char *t; @@ -859,7 +858,6 @@ char* strextend_with_separator_internal(char **x, const char *separator, ...) { need_separator = true; } - va_end(ap); assert(p == nr + l); *p = 0; @@ -872,6 +870,17 @@ char* strextend_with_separator_internal(char **x, const char *separator, ...) { return p; } +char* strextend_with_separator_internal(char **x, const char *separator, ...) { + va_list ap; + char *ret; + + va_start(ap, separator); + ret = strextendv_with_separator(x, separator, ap); + va_end(ap); + + return ret; +} + int strextendf_with_separator(char **x, const char *separator, const char *format, ...) { size_t m, a, l_separator; va_list ap; diff --git a/src/basic/string-util.h b/src/basic/string-util.h index 79e87c8914..c90134e5cd 100644 --- a/src/basic/string-util.h +++ b/src/basic/string-util.h @@ -169,6 +169,7 @@ char* strreplace(const char *text, const char *old_string, const char *new_strin char* strip_tab_ansi(char **ibuf, size_t *_isz, size_t highlight[2]); +char* strextendv_with_separator(char **x, const char *separator, va_list ap); char* strextend_with_separator_internal(char **x, const char *separator, ...) _sentinel_; #define strextend_with_separator(x, separator, ...) strextend_with_separator_internal(x, separator, __VA_ARGS__, NULL) #define strextend(x, ...) strextend_with_separator_internal(x, NULL, __VA_ARGS__, NULL) From 19bbcd35d71d48cfdea95537802c8a0d97e17be6 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 31 Oct 2025 22:19:31 +0900 Subject: [PATCH 3/7] strv: introduce strv_extend_joined() and strv_extend_joined_with_size() --- src/basic/strv.c | 12 ++++++++++++ src/basic/strv.h | 4 ++++ src/test/test-strv.c | 24 ++++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/src/basic/strv.c b/src/basic/strv.c index 4f61a42114..a19e05edc3 100644 --- a/src/basic/strv.c +++ b/src/basic/strv.c @@ -921,6 +921,18 @@ int strv_extendf_with_size(char ***l, size_t *n, const char *format, ...) { return strv_consume_with_size(l, n, x); } +int strv_extend_joined_with_size_sentinel(char ***l, size_t *n, ...) { + va_list ap; + + va_start(ap, n); + char *x = strextendv_with_separator(/* x= */ NULL, /* separator=*/ NULL, ap); + va_end(ap); + if (!x) + return -ENOMEM; + + return strv_consume_with_size(l, n, x); +} + char* startswith_strv(const char *s, char * const *l) { STRV_FOREACH(i, l) { char *found = startswith(s, *i); diff --git a/src/basic/strv.h b/src/basic/strv.h index 1133895158..7b0923a698 100644 --- a/src/basic/strv.h +++ b/src/basic/strv.h @@ -59,6 +59,10 @@ int strv_extend_many_internal(char ***l, const char *value, ...); int strv_extendf_with_size(char ***l, size_t *n, const char *format, ...) _printf_(3,4); #define strv_extendf(l, ...) strv_extendf_with_size(l, NULL, __VA_ARGS__) +int strv_extend_joined_with_size_sentinel(char ***l, size_t *n, ...) _sentinel_; +#define strv_extend_joined_with_size(l, n, ...) strv_extend_joined_with_size_sentinel(l, n, __VA_ARGS__, NULL) +#define strv_extend_joined(l, ...) strv_extend_joined_with_size(l, NULL, __VA_ARGS__) + int strv_push_with_size(char ***l, size_t *n, char *value); static inline int strv_push(char ***l, char *value) { return strv_push_with_size(l, NULL, value); diff --git a/src/test/test-strv.c b/src/test/test-strv.c index 49558850d6..b3468b1cfa 100644 --- a/src/test/test-strv.c +++ b/src/test/test-strv.c @@ -762,6 +762,30 @@ TEST(strv_extendf_with_size) { ASSERT_STREQ(a[1], "test3 bar foo 128"); } +TEST(strv_extend_joined) { + _cleanup_strv_free_ char **a = NULL; + + ASSERT_OK(strv_extend_joined(&a, "hoge")); + ASSERT_OK(strv_extend_joined(&a, "aaa", "bbb", "ccc")); + + ASSERT_EQ(strv_length(a), 2u); + ASSERT_STREQ(a[0], "hoge"); + ASSERT_STREQ(a[1], "aaabbbccc"); +} + +TEST(strv_extend_joined_with_size) { + _cleanup_strv_free_ char **a = NULL; + size_t n = 0; + + ASSERT_OK(strv_extend_joined_with_size(&a, &n, "hoge")); + ASSERT_OK(strv_extend_joined_with_size(&a, &n, "aaa", "bbb", "ccc")); + + ASSERT_EQ(n, 2u); + ASSERT_EQ(strv_length(a), n); + ASSERT_STREQ(a[0], "hoge"); + ASSERT_STREQ(a[1], "aaabbbccc"); +} + TEST(strv_foreach) { _cleanup_strv_free_ char **a; unsigned i = 0; From bafbcd3b274e94439ed3c09b1055b7cd25513d93 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 31 Oct 2025 22:30:43 +0900 Subject: [PATCH 4/7] core/exec-invoke: use heap allocation to build environment variables We sometimes forget to increase the size N_ENV_VARS. Let's use heap allocation. --- src/core/exec-invoke.c | 189 ++++++++++++++++++----------------------- 1 file changed, 82 insertions(+), 107 deletions(-) diff --git a/src/core/exec-invoke.c b/src/core/exec-invoke.c index 14e15cb8a6..e8535a176c 100644 --- a/src/core/exec-invoke.c +++ b/src/core/exec-invoke.c @@ -1999,9 +1999,8 @@ static int build_environment( bool needs_sandboxing, char ***ret) { - _cleanup_strv_free_ char **our_env = NULL; - size_t n_env = 0; - char *x; + _cleanup_strv_free_ char **e = NULL; + size_t n = 0; int r; assert(c); @@ -2009,57 +2008,50 @@ static int build_environment( assert(cgroup_context); assert(ret); -#define N_ENV_VARS 20 - our_env = new0(char*, N_ENV_VARS + _EXEC_DIRECTORY_TYPE_MAX + 1); - if (!our_env) - return -ENOMEM; - if (p->n_socket_fds + p->n_stashed_fds > 0) { _cleanup_free_ char *joined = NULL; - if (asprintf(&x, "LISTEN_PID="PID_FMT, getpid_cached()) < 0) - return -ENOMEM; - our_env[n_env++] = x; + r = strv_extendf_with_size(&e, &n, "LISTEN_PID="PID_FMT, getpid_cached()); + if (r < 0) + return r; uint64_t pidfdid; if (pidfd_get_inode_id_self_cached(&pidfdid) >= 0) { - if (asprintf(&x, "LISTEN_PIDFDID=%"PRIu64, pidfdid) < 0) - return -ENOMEM; - our_env[n_env++] = x; + r = strv_extendf_with_size(&e, &n, "LISTEN_PIDFDID=%"PRIu64, pidfdid); + if (r < 0) + return r; } - if (asprintf(&x, "LISTEN_FDS=%zu", p->n_socket_fds + p->n_stashed_fds) < 0) - return -ENOMEM; - our_env[n_env++] = x; + r = strv_extendf_with_size(&e, &n, "LISTEN_FDS=%zu", p->n_socket_fds + p->n_stashed_fds); + if (r < 0) + return r; joined = strv_join(p->fd_names, ":"); if (!joined) return -ENOMEM; - x = strjoin("LISTEN_FDNAMES=", joined); - if (!x) - return -ENOMEM; - our_env[n_env++] = x; + r = strv_extend_joined_with_size(&e, &n, "LISTEN_FDNAMES=", joined); + if (r < 0) + return r; } if ((p->flags & EXEC_SET_WATCHDOG) && p->watchdog_usec > 0) { - if (asprintf(&x, "WATCHDOG_PID="PID_FMT, getpid_cached()) < 0) - return -ENOMEM; - our_env[n_env++] = x; + r = strv_extendf_with_size(&e, &n, "WATCHDOG_PID="PID_FMT, getpid_cached()); + if (r < 0) + return r; - if (asprintf(&x, "WATCHDOG_USEC="USEC_FMT, p->watchdog_usec) < 0) - return -ENOMEM; - our_env[n_env++] = x; + r = strv_extendf_with_size(&e, &n, "WATCHDOG_USEC="USEC_FMT, p->watchdog_usec); + if (r < 0) + return r; } /* If this is D-Bus, tell the nss-systemd module, since it relies on being able to use blocking * Varlink calls back to us for look up dynamic users in PID 1. Break the deadlock between D-Bus and * PID 1 by disabling use of PID1' NSS interface for looking up dynamic users. */ if (p->flags & EXEC_NSS_DYNAMIC_BYPASS) { - x = strdup("SYSTEMD_NSS_DYNAMIC_BYPASS=1"); - if (!x) - return -ENOMEM; - our_env[n_env++] = x; + r = strv_extend_with_size(&e, &n, "SYSTEMD_NSS_DYNAMIC_BYPASS=1"); + if (r < 0) + return r; } /* We query "root" if this is a system unit and User= is not specified. $USER is always set. $HOME @@ -2077,16 +2069,14 @@ static int build_environment( bool set_user_login_env = exec_context_get_set_login_environment(c); if (username) { - x = strjoin("USER=", username); - if (!x) - return -ENOMEM; - our_env[n_env++] = x; + r = strv_extend_joined_with_size(&e, &n, "USER=", username); + if (r < 0) + return r; if (set_user_login_env) { - x = strjoin("LOGNAME=", username); - if (!x) - return -ENOMEM; - our_env[n_env++] = x; + r = strv_extend_joined_with_size(&e, &n, "LOGNAME=", username); + if (r < 0) + return r; } } @@ -2094,51 +2084,51 @@ static int build_environment( * (i.e. are "/" or "/bin/nologin"). */ if (home && set_user_login_env && !empty_or_root(home)) { - x = strjoin("HOME=", home); - if (!x) - return -ENOMEM; + _cleanup_free_ char *x = NULL; - path_simplify(x + 5); - our_env[n_env++] = x; + r = path_simplify_alloc(home, &x); + if (r < 0) + return r; + + r = strv_extend_joined_with_size(&e, &n, "HOME=", x); + if (r < 0) + return r; } if (shell && set_user_login_env && !shell_is_placeholder(shell)) { - x = strjoin("SHELL=", shell); - if (!x) - return -ENOMEM; + _cleanup_free_ char *x = NULL; - path_simplify(x + 6); - our_env[n_env++] = x; + r = path_simplify_alloc(shell, &x); + if (r < 0) + return r; + + r = strv_extend_joined_with_size(&e, &n, "SHELL=", x); + if (r < 0) + return r; } if (!sd_id128_is_null(p->invocation_id)) { assert(p->invocation_id_string); - x = strjoin("INVOCATION_ID=", p->invocation_id_string); - if (!x) - return -ENOMEM; - - our_env[n_env++] = x; + r = strv_extend_joined_with_size(&e, &n, "INVOCATION_ID=", p->invocation_id_string); + if (r < 0) + return r; } if (journal_stream_dev != 0 && journal_stream_ino != 0) { - if (asprintf(&x, "JOURNAL_STREAM=" DEV_FMT ":" INO_FMT, journal_stream_dev, journal_stream_ino) < 0) - return -ENOMEM; - - our_env[n_env++] = x; + r = strv_extendf_with_size(&e, &n, "JOURNAL_STREAM=" DEV_FMT ":" INO_FMT, journal_stream_dev, journal_stream_ino); + if (r < 0) + return r; } if (c->log_namespace) { - x = strjoin("LOG_NAMESPACE=", c->log_namespace); - if (!x) - return -ENOMEM; - - our_env[n_env++] = x; + r = strv_extend_joined_with_size(&e, &n, "LOG_NAMESPACE=", c->log_namespace); + if (r < 0) + return r; } for (ExecDirectoryType t = 0; t < _EXEC_DIRECTORY_TYPE_MAX; t++) { _cleanup_free_ char *joined = NULL; - const char *n; if (!p->prefix[t]) continue; @@ -2146,8 +2136,8 @@ static int build_environment( if (c->directories[t].n_items == 0) continue; - n = exec_directory_env_name_to_string(t); - if (!n) + const char *name = exec_directory_env_name_to_string(t); + if (!name) continue; for (size_t i = 0; i < c->directories[t].n_items; i++) { @@ -2161,11 +2151,9 @@ static int build_environment( return -ENOMEM; } - x = strjoin(n, "=", joined); - if (!x) - return -ENOMEM; - - our_env[n_env++] = x; + r = strv_extend_joined_with_size(&e, &n, name, "=", joined); + if (r < 0) + return r; } _cleanup_free_ char *creds_dir = NULL; @@ -2173,27 +2161,22 @@ static int build_environment( if (r < 0) return r; if (r > 0) { - x = strjoin("CREDENTIALS_DIRECTORY=", creds_dir); - if (!x) - return -ENOMEM; - - our_env[n_env++] = x; + r = strv_extend_joined_with_size(&e, &n, "CREDENTIALS_DIRECTORY=", creds_dir); + if (r < 0) + return r; } - if (asprintf(&x, "SYSTEMD_EXEC_PID=" PID_FMT, getpid_cached()) < 0) - return -ENOMEM; - - our_env[n_env++] = x; + r = strv_extendf_with_size(&e, &n, "SYSTEMD_EXEC_PID=" PID_FMT, getpid_cached()); + if (r < 0) + return r; if (memory_pressure_path) { - x = strjoin("MEMORY_PRESSURE_WATCH=", memory_pressure_path); - if (!x) - return -ENOMEM; - - our_env[n_env++] = x; + r = strv_extend_joined_with_size(&e, &n, "MEMORY_PRESSURE_WATCH=", memory_pressure_path); + if (r < 0) + return r; if (!path_equal(memory_pressure_path, "/dev/null")) { - _cleanup_free_ char *b = NULL, *e = NULL; + _cleanup_free_ char *b = NULL, *x = NULL; if (asprintf(&b, "%s " USEC_FMT " " USEC_FMT, MEMORY_PRESSURE_DEFAULT_TYPE, @@ -2202,23 +2185,21 @@ static int build_environment( MEMORY_PRESSURE_DEFAULT_WINDOW_USEC) < 0) return -ENOMEM; - if (base64mem(b, strlen(b) + 1, &e) < 0) + if (base64mem(b, strlen(b) + 1, &x) < 0) return -ENOMEM; - x = strjoin("MEMORY_PRESSURE_WRITE=", e); - if (!x) - return -ENOMEM; - - our_env[n_env++] = x; + r = strv_extend_joined_with_size(&e, &n, "MEMORY_PRESSURE_WRITE=", x); + if (r < 0) + return r; } } if (p->notify_socket) { - x = strjoin("NOTIFY_SOCKET=", exec_get_private_notify_socket_path(c, p, needs_sandboxing) ?: p->notify_socket); - if (!x) - return -ENOMEM; - - our_env[n_env++] = x; + r = strv_extend_joined_with_size( + &e, &n, "NOTIFY_SOCKET=", + exec_get_private_notify_socket_path(c, p, needs_sandboxing) ?: p->notify_socket); + if (r < 0) + return r; } assert(c->private_var_tmp >= 0 && c->private_var_tmp < _PRIVATE_TMP_MAX); @@ -2229,18 +2210,12 @@ static int build_environment( /* When private tmpfs is enabled only on /tmp/, then explicitly set $TMPDIR to suggest the * service to use /tmp/. */ - x = strdup("TMPDIR=/tmp"); - if (!x) - return -ENOMEM; - - our_env[n_env++] = x; + r = strv_extend_with_size(&e, &n, "TMPDIR=/tmp"); + if (r < 0) + return r; } - assert(n_env <= N_ENV_VARS + _EXEC_DIRECTORY_TYPE_MAX); -#undef N_ENV_VARS - - *ret = TAKE_PTR(our_env); - + *ret = TAKE_PTR(e); return 0; } From 2b2b04d6d06d8bd23807bc6e7686512efde01842 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 31 Oct 2025 22:36:41 +0900 Subject: [PATCH 5/7] dns-rr: use strv_extendf() at one more place --- src/shared/dns-rr.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/shared/dns-rr.c b/src/shared/dns-rr.c index 7960002914..32c26a7612 100644 --- a/src/shared/dns-rr.c +++ b/src/shared/dns-rr.c @@ -819,21 +819,12 @@ static char *format_types(Bitmap *types) { int r; BITMAP_FOREACH(type, types) { - if (dns_type_to_string(type)) { + if (dns_type_to_string(type)) r = strv_extend(&strv, dns_type_to_string(type)); - if (r < 0) - return NULL; - } else { - char *t; - - r = asprintf(&t, "TYPE%u", type); - if (r < 0) - return NULL; - - r = strv_consume(&strv, t); - if (r < 0) - return NULL; - } + else + r = strv_extendf(&strv, "TYPE%u", type); + if (r < 0) + return NULL; } str = strv_join(strv, " "); From 323fafbb556b69b59be7646f1f1aa4f42e26f5d9 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 31 Oct 2025 22:45:05 +0900 Subject: [PATCH 6/7] vmspawn: use strv_extendf() at one more place --- src/vmspawn/vmspawn.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/vmspawn/vmspawn.c b/src/vmspawn/vmspawn.c index 14ae20fbe3..76787013fd 100644 --- a/src/vmspawn/vmspawn.c +++ b/src/vmspawn/vmspawn.c @@ -1933,11 +1933,10 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) { return log_error_errno(r, "Failed to make up randomized vmgenid: %m"); } - _cleanup_free_ char *vmgenid_device = NULL; - if (asprintf(&vmgenid_device, "vmgenid,guid=" SD_ID128_UUID_FORMAT_STR, SD_ID128_FORMAT_VAL(vmgenid)) < 0) + if (strv_extend(&cmdline, "-device") < 0) return log_oom(); - if (strv_extend_many(&cmdline, "-device", vmgenid_device) < 0) + if (strv_extendf(&cmdline, "vmgenid,guid=" SD_ID128_UUID_FORMAT_STR, SD_ID128_FORMAT_VAL(vmgenid)) < 0) return log_oom(); } From 154de15bdfc2b08c5db90a0c03d9482b55491b6d Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 31 Oct 2025 22:46:42 +0900 Subject: [PATCH 7/7] vmspawn: replace strv_extendf() with strv_extend_joined() when concatenating strings --- src/vmspawn/vmspawn.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/vmspawn/vmspawn.c b/src/vmspawn/vmspawn.c index 76787013fd..633e6a25ca 100644 --- a/src/vmspawn/vmspawn.c +++ b/src/vmspawn/vmspawn.c @@ -1154,7 +1154,7 @@ static int cmdline_add_kernel_cmdline(char ***cmdline, const char *kernel, const if (strv_extend(cmdline, "-smbios") < 0) return log_oom(); - if (strv_extendf(cmdline, "type=11,path=%s", p) < 0) + if (strv_extend_joined(cmdline, "type=11,path=", p) < 0) return log_oom(); } } @@ -1191,7 +1191,7 @@ static int cmdline_add_smbios11(char ***cmdline, const char* smbios_dir) { if (strv_extend(cmdline, "-smbios") < 0) return log_oom(); - if (strv_extendf(cmdline, "type=11,path=%s", p) < 0) + if (strv_extend_joined(cmdline, "type=11,path=", p) < 0) return log_oom(); p = mfree(p); @@ -1289,7 +1289,7 @@ static int start_tpm( if (!argv) return log_oom(); - r = strv_extendf(&argv, "dir=%s", state_dir); + r = strv_extend_joined(&argv, "dir=", state_dir); if (r < 0) return log_oom(); @@ -2150,8 +2150,7 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) { "-chardev") < 0) return log_oom(); - if (strv_extendf(&cmdline, - "serial,id=console,path=%s", pty_path) < 0) + if (strv_extend_joined(&cmdline, "serial,id=console,path=", pty_path) < 0) return log_oom(); r = strv_extend_many( @@ -2281,7 +2280,7 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) { if (strv_extend(&cmdline, "-device") < 0) return log_oom(); - if (strv_extendf(&cmdline, "virtio-blk-pci,drive=vmspawn,bootindex=1,serial=%s", escaped_image_fn) < 0) + if (strv_extend_joined(&cmdline, "virtio-blk-pci,drive=vmspawn,bootindex=1,serial=", escaped_image_fn) < 0) return log_oom(); r = grow_image(arg_image, arg_grow_image); @@ -2551,7 +2550,7 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) { if (strv_extend(&cmdline, "-chardev") < 0) return log_oom(); - if (strv_extendf(&cmdline, "socket,id=chrtpm,path=%s", tpm_socket_address) < 0) + if (strv_extend_joined(&cmdline, "socket,id=chrtpm,path=", tpm_socket_address) < 0) return log_oom(); if (strv_extend_many(&cmdline, "-tpmdev", "emulator,id=tpm0,chardev=chrtpm") < 0) @@ -2686,7 +2685,7 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) { if (r < 0) return log_oom(); - r = strv_extendf(&cmdline, "type=11,path=%s", p); + r = strv_extend_joined(&cmdline, "type=11,path=", p); if (r < 0) return log_oom(); }