git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Add ability to specify environment extension to run_command

From
Alex Riesen <raa.lkml@gmail.com>
Date
May 22, 2007, 23:14 UTC
Message-ID
<20070522231442.GM30871@steel.home>
In-Reply-To
<7v1wh88prw.fsf@assigned-by-dhcp.cox.net>
Junio C Hamano, Wed, May 23, 2007 00:19:47 +0200:
Show 15 quoted lines
> > Others already discussed the issue. Just to be sure, I reimplemented
> > that comfortable putenv with unsetenv: if an environment entry ends
> > with a "=" it will be unset.
> 
> Although combination of putenv and unsetenv gives a somewhat
> queasy feeling for obvious reasons, I'll let it pass.  As we
> are coming up with an interface that uses only one string per
> environment element, that is probably a sensible thing to do,
> rather than trying to do the "historically correct" pairing of
> setenv/unsetenv.
> 
> However, I do not think "VAR=" to unset it is a good interface.
> Having an environment variable whose value happens to be an
> empty string and not having the variable at all are two
> different things.
Right
Show 7 quoted lines
> Because you _scan_ the whole string in your patch to see if it
> ends with = anyway, a trivial improvement would be to do:
> 
> 	if (strchr(cmd->env, '='))
>                 putenv(cmd->env);
> 	else
>         	unsetenv(cmd->env);

I like this one. The env field in struct child_process and run_command will have to mention it in comments (in run-command.h), it's kind of special.

> If you do not mind such a special syntax (e.g. "VAR="), I would
> suggest doing that as a prefix (e.g. "!VAR") and do:
Nah, !VAR is a _working_ environment variable name.
    int main(int argc, char *argv[], char *envp[])
    {
	    const char *argv1[] = {"/usr/bin/perl", "-e", "print $ENV{'!VAR'}", NULL};
	    const char *envp1[] = {"!VAR=value", NULL};
	    execve(*argv, (char**)argv1, (char**)envp1);
	    return 0;
    }
    $ gcc ... && ./a.out
    value
Someone could want it. We surely could use "=", though :)
Previous: Junio C HamanoNext: Alex Riesen
Message 19 of 20 in “allow commands to be executed in submodules”
  1. allow commands to be executed in submodulesMartin Waitz, May 20, 2007
  2. Alex RiesenMay 20, 2007
  3. Junio C HamanoMay 20, 2007
  4. Martin WaitzMay 20, 2007
  5. Alex RiesenMay 20, 2007
  6. Martin WaitzMay 20, 2007
  7. Add ability to specify environment extension to run_commandAlex Riesen, May 21, 2007
  8. Junio C HamanoMay 21, 2007
  9. Martin WaitzMay 22, 2007
  10. Junio C HamanoMay 22, 2007
  11. Shawn O. PearceMay 22, 2007
  12. Sven VerdoolaegeMay 22, 2007
  13. Alex RiesenMay 22, 2007
  14. Alex RiesenMay 22, 2007
  15. Add run_command_v_opt_cd: chdir into a directory before execAlex Riesen, May 22, 2007
  16. Add ability to specify environment extension to run_commandAlex Riesen, May 22, 2007
  17. Allow environment variables to be unset in the processes started by run_commandAlex Riesen, May 22, 2007
  18. Junio C HamanoMay 22, 2007
  19. Alex RiesenMay 22, 2007
  20. Allow environment variables to be unset in the processes started by run_commandAlex Riesen, May 23, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.