git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Duy Nguyen <pclouds@gmail.com>,
	Git Mailing List <git@vger.kernel.org>,
	Stefan Beller <sbeller@google.com>,
	Anthony Sottile <asottile@umich.edu>
Subject: Re: [PATCH v2 0/3] nd/clear-gitenv-upon-use-of-alias
Date: Wed, 23 Dec 2015 04:37:00 -0500	[thread overview]
Message-ID: <20151223093700.GA13386@sigill.intra.peff.net> (raw)
In-Reply-To: <xmqqd1tye4i8.fsf@gitster.mtv.corp.google.com>

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.

-- >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

  reply	other threads:[~2015-12-23  9:37 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CA+dzEB=2LJXiLSTqyLw8AeHNwdQicwvEiMg=hVEX0-_s1bySpA@mail.gmail.com>
2015-11-24  2:22 ` Fwd: Git clone fails during pre-commit hook due to GIT_WORK_TREE=. (regression 2.5 -> 2.6) Anthony Sottile
2015-11-24 17:57   ` Stefan Beller
2015-11-25 20:13     ` Duy Nguyen
2015-11-30 19:01       ` Duy Nguyen
2015-11-30 20:16         ` Junio C Hamano
2015-12-01 17:59           ` Duy Nguyen
2015-12-02 17:09             ` Junio C Hamano
2015-12-03 18:17               ` [PATCH 1/2] git.c: make it clear save_env() is for alias handling only Nguyễn Thái Ngọc Duy
2015-12-03 18:17                 ` [PATCH 2/2] setup.c: re-fix d95138e (setup: set env $GIT_WORK_TREE when Nguyễn Thái Ngọc Duy
2015-12-04 20:35                   ` Junio C Hamano
2015-12-05  5:48                     ` Duy Nguyen
2015-12-05 15:32                   ` [PATCH 3/2] git.c: make sure we do not leak GIT_* to alias scripts Nguyễn Thái Ngọc Duy
2015-12-07 18:54                     ` Junio C Hamano
2015-12-08 16:55                       ` Duy Nguyen
2015-12-08 17:20                         ` Jeff King
2015-12-08 23:55                           ` Junio C Hamano
2015-12-05 19:12                   ` [PATCH 2/2] setup.c: re-fix d95138e (setup: set env $GIT_WORK_TREE when Duy Nguyen
2015-12-07 18:33                     ` Junio C Hamano
2015-12-20  7:50                 ` [PATCH v2 0/3] nd/clear-gitenv-upon-use-of-alias Nguyễn Thái Ngọc Duy
2015-12-20  7:50                   ` [PATCH v2 1/3] git.c: make it clear save_env() is for alias handling only Nguyễn Thái Ngọc Duy
2015-12-20  7:50                   ` [PATCH v2 2/3] setup.c: re-fix d95138e (setup: set env $GIT_WORK_TREE when Nguyễn Thái Ngọc Duy
2015-12-20  7:50                   ` [PATCH v2 3/3] git.c: make sure we do not leak GIT_* to alias scripts Nguyễn Thái Ngọc Duy
2015-12-21 21:18                   ` [PATCH v2 0/3] nd/clear-gitenv-upon-use-of-alias Junio C Hamano
2015-12-22 10:57                     ` Duy Nguyen
2015-12-22 11:53                       ` Duy Nguyen
2015-12-22 18:13                         ` Junio C Hamano
2015-12-23  9:37                           ` Jeff King [this message]
2015-12-23 10:20                             ` Duy Nguyen
2015-12-23 16:17                             ` Eric Sunshine
2015-12-23 20:37                             ` Johannes Sixt
2015-12-23 21:31                               ` Jeff King
2015-12-24  9:35                                 ` Duy Nguyen
2015-12-29  8:12                                   ` Jeff King
2015-12-29 21:34                                     ` Junio C Hamano
2015-12-21 10:22               ` [PATCH] Revert "setup: set env $GIT_WORK_TREE when work tree is set, like $GIT_DIR" Nguyễn Thái Ngọc Duy
2015-12-21 17:28                 ` Junio C Hamano
2015-12-21 18:31                   ` Junio C Hamano
2015-12-22  1:06                     ` Duy Nguyen
2015-12-22 21:50                       ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151223093700.GA13386@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=asottile@umich.edu \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pclouds@gmail.com \
    --cc=sbeller@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).