From: Alex Riesen Date: Tue, 22 May 2007 21:49:21 GMT Subject: [PATCH] Allow environment variables to be unset in the processes started by run_command Message-ID: <20070522214921.GG30871@steel.home> In-Reply-To: <20070522214847.GF30871@steel.home> Signed-off-by: Alex Riesen --- run-command.c | 14 ++++++++++++-- 1 files changed, 12 insertions(+), 2 deletions(-) diff --git a/run-command.c b/run-command.c index 605aa1e..3a5f737 100644 --- a/run-command.c +++ b/run-command.c @@ -77,8 +77,18 @@ int start_command(struct child_process *cmd) die("exec %s: cd to %s failed (%s)", cmd->argv[0], cmd->dir, strerror(errno)); if (cmd->env) { - for (; *cmd->env; cmd->env++) - putenv((char*)*cmd->env); + char *unsetbuf = NULL; + for (; *cmd->env; cmd->env++) { + size_t n = strlen(*cmd->env); + if (n && (*cmd->env)[n-1] == '=') { + unsetbuf = xrealloc(unsetbuf, n); + memcpy(unsetbuf, *cmd->env, --n); + unsetbuf[n] = '\0'; + unsetenv(unsetbuf); + } else + putenv((char*)*cmd->env); + } + free(unsetbuf); } if (cmd->git_cmd) { execv_git_cmd(cmd->argv); -- 1.5.2.51.g16099