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

Re: [PATCH v2 0/3] nd/clear-gitenv-upon-use-of-alias

From
Duy Nguyen <pclouds@gmail.com>
Date
Dec 23, 2015, 10:20 UTC
Message-ID
<CACsJy8AwoohWmUF9QCDg+xvNifDh0o+PBnExxwv=qxz2Mh4a1w@mail.gmail.com>
In-Reply-To
<20151223093700.GA13386@sigill.intra.peff.net>
On Wed, Dec 23, 2015 at 4:37 PM, Jeff King <peff@peff.net> wrote:
Show 25 quoted lines
> On Tue, Dec 22, 2015 at 10:13:03AM -0800, Junio C Hamano wrote:
>
>> > Another by the way, this "forcing aliases as external commands" now
>> > shows something like "error: git-log died of signal 13" when the pager
>> > exits early, for an alias like "l1 = log --oneline".
>>
>> ... and we do not show that when we directly call "git log" is...?
>>
>> We do signal this with non-zero exit status like so:
>>
>>       $ GIT_PAGER=true git log --oneline ; echo $?
>>         141
>>
>> and it is not surprising that the one that is catching the exit
>> status of what was spawned and reporting "signal 13".
>
> This sounded very familiar. Apparently I've been running with the patch
> below for almost 3 years and never got around to re-examining it.
>
> The original discussion is in:
>
>   http://thread.gmane.org/gmane.comp.version-control.git/212630
>
> Having skimmed through the arguments there, and given that we applied
> the patch from the middle of the thread, I think this is a good change.

Yep. The new thing here is the "died of" message now also comes from execv_dashed_external() for non-external aliases, so it can show up a lot more often. I wasn't sure if excluding SIGPIPE in wait_and_whine was safe. But I _guess_ it is, based on your having no problem with the patch for a long time and the past discussion.

Show 89 quoted lines
>
> -- >8 --
> Date: Fri, 4 Jan 2013 07:19:35 -0500
> Subject: [PATCH] avoid SIGPIPE warnings for aliases
>
> When git executes an alias that specifies an external
> command, it will complain if the alias dies due to a signal.
> This is usually a good thing, as signal deaths are
> unexpected. However, SIGPIPE is not unexpected for many
> commands which produce a lot of output; it is intended that
> the user closing the pager would kill them them via SIGPIPE.
>
> As a result, the user might see annoying messages in a
> scenario like this:
>
>   $ cat ~/.gitconfig
>   [alias]
>   lgbase = log --some-options
>   lg = !git lgbase --more-options
>   lg2 = !git lgbase --other-options
>
>   $ git lg -p
>   [user hits 'q' to exit pager]
>   error: git lgbase --more-options died of signal 13
>   fatal: While expanding alias 'lg': 'git lgbase --more-options': Success
>
> Many users won't see this, because we execute the external
> command with the shell, and a POSIX shell will silently
> rewrite the signal-death exit code into 128+signal, and we
> will treat it like a normal exit code. However, this does
> not always happen:
>
>   1. If the sub-command does not have shell metacharacters,
>      we will skip the shell and exec it directly, getting
>      the signal code.
>
>   2. Some shells do not do this rewriting; for example,
>      setting SHELL_PATH set to zsh will reveal this problem.
>
> This patch squelches the message, and lets git exit silently
> (with the same exit code that a shell would use in case of a
> signal).
>
> The first line of the message comes from run-command's
> wait_or_whine. To silence that message, we remain quiet
> anytime we see SIGPIPE.
>
> The second line comes from handle_alias itself. It calls
> die_errno whenever run_command returns a negative value.
> However, only -1 indicates a syscall error where errno has
> something useful (note that it says the useless "success"
> above). Instead, we treat negative returns from run_command
> (except for -1) as a normal code to be passed to exit.
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
>  git.c         | 2 +-
>  run-command.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/git.c b/git.c
> index 6ed824c..34a18a3 100644
> --- a/git.c
> +++ b/git.c
> @@ -252,7 +252,7 @@ static int handle_alias(int *argcp, const char ***argv)
>                         alias_argv[argc] = NULL;
>
>                         ret = run_command_v_opt(alias_argv, RUN_USING_SHELL);
> -                       if (ret >= 0)   /* normal exit */
> +                       if (ret != -1)  /* normal exit */
>                                 exit(ret);
>
>                         die_errno("While expanding alias '%s': '%s'",
> diff --git a/run-command.c b/run-command.c
> index 13fa452..694a6ff 100644
> --- a/run-command.c
> +++ b/run-command.c
> @@ -245,7 +245,7 @@ static int wait_or_whine(pid_t pid, const char *argv0, int in_signal)
>                 error("waitpid is confused (%s)", argv0);
>         } else if (WIFSIGNALED(status)) {
>                 code = WTERMSIG(status);
> -               if (code != SIGINT && code != SIGQUIT)
> +               if (code != SIGINT && code != SIGQUIT && code != SIGPIPE)
>                         error("%s died of signal %d", argv0, code);
>                 /*
>                  * This return value is chosen so that code & 0xff
> --
> 2.7.0.rc2.368.g1cbb535
>
-- 
Duy
Previous: Jeff KingNext: Eric Sunshine
Message 28 of 39 in “Fwd: Git clone fails during pre-commit hook due to GIT_WORK_TREE=. (regression 2.5 -> 2.6)”
  1. Anthony SottileNov 24, 2015
  2. Stefan BellerNov 24, 2015
  3. Duy NguyenNov 25, 2015
  4. Duy NguyenNov 30, 2015
  5. Junio C HamanoNov 30, 2015
  6. Duy NguyenDec 1, 2015
  7. Junio C HamanoDec 2, 2015
  8. 1/2 git.c: make it clear save_env() is for alias handling onlyNguyễn Thái Ngọc Duy, Dec 3, 2015
  9. 2/2 setup.c: re-fix d95138e (setup: set env $GIT_WORK_TREE when ..Nguyễn Thái Ngọc Duy, Dec 3, 2015
  10. Junio C HamanoDec 4, 2015
  11. Duy NguyenDec 5, 2015
  12. 3/2 git.c: make sure we do not leak GIT_* to alias scriptsNguyễn Thái Ngọc Duy, Dec 5, 2015
  13. Junio C HamanoDec 7, 2015
  14. Duy NguyenDec 8, 2015
  15. Jeff KingDec 8, 2015
  16. Junio C HamanoDec 8, 2015
  17. Duy NguyenDec 5, 2015
  18. Junio C HamanoDec 7, 2015
  19. 0/3 nd/clear-gitenv-upon-use-of-aliasNguyễn Thái Ngọc Duy, Dec 20, 2015
  20. 1/3 git.c: make it clear save_env() is for alias handling onlyNguyễn Thái Ngọc Duy, Dec 20, 2015
  21. 2/3 setup.c: re-fix d95138e (setup: set env $GIT_WORK_TREE when ..Nguyễn Thái Ngọc Duy, Dec 20, 2015
  22. 3/3 git.c: make sure we do not leak GIT_* to alias scriptsNguyễn Thái Ngọc Duy, Dec 20, 2015
  23. Junio C HamanoDec 21, 2015
  24. Duy NguyenDec 22, 2015
  25. Duy NguyenDec 22, 2015
  26. Junio C HamanoDec 22, 2015
  27. Jeff KingDec 23, 2015
  28. Duy NguyenDec 23, 2015
  29. Eric SunshineDec 23, 2015
  30. Johannes SixtDec 23, 2015
  31. Jeff KingDec 23, 2015
  32. Duy NguyenDec 24, 2015
  33. Jeff KingDec 29, 2015
  34. Junio C HamanoDec 29, 2015
  35. Revert "setup: set env $GIT_WORK_TREE when work tree is set, like $GIT_DIR"Nguyễn Thái Ngọc Duy, Dec 21, 2015
  36. Junio C HamanoDec 21, 2015
  37. Junio C HamanoDec 21, 2015
  38. Duy NguyenDec 22, 2015
  39. Junio C HamanoDec 22, 2015

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.