Add implicit sentinel to strv_env_merge()
Just to make it a tiny bit nicer to use.
This commit is contained in:
+10
-10
@@ -3189,8 +3189,8 @@ static int inner_child(
|
||||
_cleanup_free_ char *home = NULL;
|
||||
char as_uuid[ID128_UUID_STRING_MAX];
|
||||
size_t n_env = 1;
|
||||
const char *envp[] = {
|
||||
"PATH=" DEFAULT_PATH_COMPAT,
|
||||
char *envp[] = {
|
||||
(char*) "PATH=" DEFAULT_PATH_COMPAT,
|
||||
NULL, /* container */
|
||||
NULL, /* TERM */
|
||||
NULL, /* HOME */
|
||||
@@ -3426,17 +3426,17 @@ static int inner_child(
|
||||
n_env++;
|
||||
|
||||
if (home || !uid_is_valid(arg_uid) || arg_uid == 0)
|
||||
if (asprintf((char**)(envp + n_env++), "HOME=%s", home ?: "/root") < 0)
|
||||
if (asprintf(envp + n_env++, "HOME=%s", home ?: "/root") < 0)
|
||||
return log_oom();
|
||||
|
||||
if (arg_user || !uid_is_valid(arg_uid) || arg_uid == 0)
|
||||
if (asprintf((char**)(envp + n_env++), "USER=%s", arg_user ?: "root") < 0 ||
|
||||
asprintf((char**)(envp + n_env++), "LOGNAME=%s", arg_user ? arg_user : "root") < 0)
|
||||
if (asprintf(envp + n_env++, "USER=%s", arg_user ?: "root") < 0 ||
|
||||
asprintf(envp + n_env++, "LOGNAME=%s", arg_user ? arg_user : "root") < 0)
|
||||
return log_oom();
|
||||
|
||||
assert(!sd_id128_is_null(arg_uuid));
|
||||
|
||||
if (asprintf((char**)(envp + n_env++), "container_uuid=%s", id128_to_uuid_string(arg_uuid, as_uuid)) < 0)
|
||||
if (asprintf(envp + n_env++, "container_uuid=%s", id128_to_uuid_string(arg_uuid, as_uuid)) < 0)
|
||||
return log_oom();
|
||||
|
||||
if (fdset_size(fds) > 0) {
|
||||
@@ -3444,11 +3444,11 @@ static int inner_child(
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to unset O_CLOEXEC for file descriptors.");
|
||||
|
||||
if ((asprintf((char **)(envp + n_env++), "LISTEN_FDS=%u", fdset_size(fds)) < 0) ||
|
||||
(asprintf((char **)(envp + n_env++), "LISTEN_PID=1") < 0))
|
||||
if ((asprintf(envp + n_env++, "LISTEN_FDS=%u", fdset_size(fds)) < 0) ||
|
||||
(asprintf(envp + n_env++, "LISTEN_PID=1") < 0))
|
||||
return log_oom();
|
||||
}
|
||||
if (asprintf((char **)(envp + n_env++), "NOTIFY_SOCKET=%s", NSPAWN_NOTIFY_SOCKET_PATH) < 0)
|
||||
if (asprintf(envp + n_env++, "NOTIFY_SOCKET=%s", NSPAWN_NOTIFY_SOCKET_PATH) < 0)
|
||||
return log_oom();
|
||||
|
||||
if (arg_n_credentials > 0) {
|
||||
@@ -3458,7 +3458,7 @@ static int inner_child(
|
||||
n_env++;
|
||||
}
|
||||
|
||||
env_use = strv_env_merge(3, envp, os_release_pairs, arg_setenv);
|
||||
env_use = strv_env_merge(envp, os_release_pairs, arg_setenv);
|
||||
if (!env_use)
|
||||
return log_oom();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user