diff options
| author | Denys Vlasenko <dvlasenk@redhat.com> | 2011-03-08 14:07:33 +0100 |
|---|---|---|
| committer | Denys Vlasenko <dvlasenk@redhat.com> | 2011-03-08 14:07:33 +0100 |
| commit | abb11fca1bcd7932d14c911d63fb7c6c347dcbcd (patch) | |
| tree | 219ca2f09a7f8d7c310aca9456624a7f37b8716b /src/lib/spawn.c | |
| parent | 077b157218254437185b5cb9d0267df72a918b79 (diff) | |
| download | abrt-abb11fca1bcd7932d14c911d63fb7c6c347dcbcd.tar.gz abrt-abb11fca1bcd7932d14c911d63fb7c6c347dcbcd.tar.xz abrt-abb11fca1bcd7932d14c911d63fb7c6c347dcbcd.zip | |
make fork_execv_on_steroids capable of setting env vars too
Before, it could only unset them.
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'src/lib/spawn.c')
| -rw-r--r-- | src/lib/spawn.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/lib/spawn.c b/src/lib/spawn.c index f6b7263c..188b63bd 100644 --- a/src/lib/spawn.c +++ b/src/lib/spawn.c @@ -32,7 +32,7 @@ static char *concat_str_vector(char **strings) pid_t fork_execv_on_steroids(int flags, char **argv, int *pipefds, - char **unsetenv_vec, + char **env_vec, const char *dir, uid_t uid) { @@ -69,9 +69,11 @@ pid_t fork_execv_on_steroids(int flags, xsetreuid(uid, uid); } - if (unsetenv_vec) { - while (*unsetenv_vec) - unsetenv(*unsetenv_vec++); + if (env_vec) { + /* Note: we use the glibc extension that putenv("var") + * *unsets* $var if "var" string has no '=' */ + while (*env_vec) + putenv(*env_vec++); } /* Play with stdio descriptors */ @@ -134,7 +136,7 @@ char *run_in_shell_and_save_output(int flags, const char *argv[] = { "/bin/sh", "-c", cmd, NULL }; int pipeout[2]; pid_t child = fork_execv_on_steroids(flags, (char **)argv, pipeout, - /*unsetenv_vec:*/ NULL, dir, /*uid (unused):*/ 0); + /*env_vec:*/ NULL, dir, /*uid (unused):*/ 0); size_t pos = 0; char *result = NULL; |
