Commit d6411e8a authored by David Zeuthen's avatar David Zeuthen

fix a bug where the childs environment wasn't inherited

parent b68d89a4
......@@ -178,7 +178,6 @@ kit_spawn_sync (const char *working_directory,
{
kit_bool_t ret;
pid_t pid;
char **envp_to_use;
int stdin_pipe[2] = {-1, -1};
int stdout_pipe[2] = {-1, -1};
int stderr_pipe[2] = {-1, -1};
......@@ -197,11 +196,6 @@ kit_spawn_sync (const char *working_directory,
if (stderr != NULL)
*stderr = NULL;
if (envp != NULL)
envp_to_use = envp;
else
envp_to_use = environ;
if (stdin != NULL) {
if (pipe (stdin_pipe) != 0) {
goto out;
......@@ -298,8 +292,14 @@ kit_spawn_sync (const char *working_directory,
close (fd_null);
/* finally, execute the child */
if (execve (argv[0], argv, envp_to_use) == -1) {
exit (128 + errno);
if (envp != NULL) {
if (execve (argv[0], argv, envp) == -1) {
exit (128 + errno);
}
} else {
if (execv (argv[0], argv) == -1) {
exit (128 + errno);
}
}
} else {
......@@ -459,6 +459,13 @@ _run_test (void)
" exit 0" "\n"
"fi" "\n"
"exit 1" "\n";
char *script4b =
"#!/bin/sh" "\n"
"/bin/env > /tmp/food2" "\n"
"if [ \"x$KIT_TEST_VAR\" = \"xfoobar2\" ] ; then" "\n"
" exit 0" "\n"
"fi" "\n"
"exit 1" "\n";
char *script5 =
"#!/bin/sh" "\n"
"pwd" "\n"
......@@ -567,6 +574,26 @@ _run_test (void)
kit_assert (unsetenv ("KIT_TEST_VAR") == 0);
}
/* check environment is inherited */
if (kit_file_set_contents (path, 0700, script4b, strlen (script4b))) {
kit_assert (setenv ("KIT_TEST_VAR", "foobar2", 1) == 0);
if (kit_spawn_sync ("/",
0,
argv,
NULL,
NULL,
NULL,
NULL,
&exit_status)) {
kit_assert (WEXITSTATUS (exit_status) == 0);
}
kit_assert (unlink (path) == 0);
kit_assert (unsetenv ("KIT_TEST_VAR") == 0);
}
/* check working directory */
if (kit_file_set_contents (path, 0700, script5, strlen (script5))) {
kit_assert (stat ("/tmp", &statbuf) == 0 && S_ISDIR (statbuf.st_mode));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment