Several cleanups around strv_extendf() (#39508)
This commit is contained in:
+17
-8
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
+14
-2
@@ -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,19 @@ 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);
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
+6
-1
@@ -56,7 +56,12 @@ 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_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) {
|
||||
|
||||
+82
-107
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+5
-14
@@ -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, " ");
|
||||
|
||||
@@ -749,6 +749,43 @@ 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_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;
|
||||
|
||||
+9
-11
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -2151,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(
|
||||
@@ -2282,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);
|
||||
@@ -2552,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)
|
||||
@@ -2687,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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user