diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-10-19 01:48:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-19 01:48:37 +0200 |
commit | b0b8c9a5a45da32f261b91d0a777661339290cf4 (patch) | |
tree | 28fbf54ea07f065666e6641cc5fa4a758139898f /src | |
parent | Merge pull request #10450 from poettering/foreach-line-excorcism (diff) | |
parent | test: check for putenv() failures, the call might theortically fail (diff) | |
download | systemd-b0b8c9a5a45da32f261b91d0a777661339290cf4.tar.xz systemd-b0b8c9a5a45da32f261b91d0a777661339290cf4.zip |
Merge pull request #10389 from poettering/nspawn-path-fix
nspawn $PATH execvpe() fix
Diffstat (limited to 'src')
-rw-r--r-- | src/basic/exec-util.c | 2 | ||||
-rw-r--r-- | src/nspawn/nspawn.c | 11 | ||||
-rw-r--r-- | src/test/test-proc-cmdline.c | 4 |
3 files changed, 14 insertions, 3 deletions
diff --git a/src/basic/exec-util.c b/src/basic/exec-util.c index 32c6418482..a6c020b0f8 100644 --- a/src/basic/exec-util.c +++ b/src/basic/exec-util.c @@ -102,7 +102,7 @@ static int do_execute( alarm(DIV_ROUND_UP(timeout, USEC_PER_SEC)); STRV_FOREACH(e, envp) - if (putenv(*e) < 0) + if (putenv(*e) != 0) return log_error_errno(errno, "Failed to set environment variable: %m"); STRV_FOREACH(path, paths) { diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 88138d7d9d..d6a7d5b9ad 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -2795,7 +2795,18 @@ static int inner_child( exec_target = "/usr/lib/systemd/systemd, /lib/systemd/systemd, /sbin/init"; } else if (!strv_isempty(arg_parameters)) { + const char *dollar_path; + exec_target = arg_parameters[0]; + + /* Use the user supplied search $PATH if there is one, or DEFAULT_PATH_COMPAT if not to search the + * binary. */ + dollar_path = strv_env_get(env_use, "PATH"); + if (dollar_path) { + if (putenv((char*) dollar_path) != 0) + return log_error_errno(errno, "Failed to update $PATH: %m"); + } + execvpe(arg_parameters[0], arg_parameters, env_use); } else { if (!arg_chdir) diff --git a/src/test/test-proc-cmdline.c b/src/test/test-proc-cmdline.c index 5db103bd22..1b6724755f 100644 --- a/src/test/test-proc-cmdline.c +++ b/src/test/test-proc-cmdline.c @@ -82,7 +82,7 @@ static void test_proc_cmdline_get_key(void) { _cleanup_free_ char *value = NULL; log_info("/* %s */", __func__); - putenv((char*) "SYSTEMD_PROC_CMDLINE=foo_bar=quux wuff-piep=tuet zumm"); + assert_se(putenv((char*) "SYSTEMD_PROC_CMDLINE=foo_bar=quux wuff-piep=tuet zumm") == 0); assert_se(proc_cmdline_get_key("", 0, &value) == -EINVAL); assert_se(proc_cmdline_get_key("abc", 0, NULL) == 0); @@ -120,7 +120,7 @@ static void test_proc_cmdline_get_bool(void) { bool value = false; log_info("/* %s */", __func__); - putenv((char*) "SYSTEMD_PROC_CMDLINE=foo_bar bar-waldo=1 x_y-z=0 quux=miep"); + assert_se(putenv((char*) "SYSTEMD_PROC_CMDLINE=foo_bar bar-waldo=1 x_y-z=0 quux=miep") == 0); assert_se(proc_cmdline_get_bool("", &value) == -EINVAL); assert_se(proc_cmdline_get_bool("abc", &value) == 0 && value == false); |