# [PATCH v2] diff-highlight: exit when a pipe is broken

3 messages from 2014-11-04 to 2014-11-04. Participants: John Szakmeister, Jeff King, Junio C Hamano.
Thread: https://gitlist.dev/t/37877

## John Szakmeister, 2014-11-04 20:01

Subject: [PATCH v2] diff-highlight: exit when a pipe is broken
Message-ID: <1415131272-89441-1-git-send-email-john@szakmeister.net>
URL: https://gitlist.dev/e/1415131272-89441-1-git-send-email-john%40szakmeister.net

```
While using diff-highlight with other tools, I have discovered that Python
ignores SIGPIPE by default.  Unfortunately, this also means that tools
attempting to launch a pager under Python--and don't realize this is
happening--means that the subprocess inherits this setting.  In this case, it
means diff-highlight will be launched with SIGPIPE being ignored.  Let's work
with those broken scripts by restoring the default SIGPIPE handler.

Signed-off-by: John Szakmeister <john@szakmeister.net>
---
Incorporates feedback from Jeff King and now we just restore the default signal
handler using the correct case of 'DEFAULT'.

 contrib/diff-highlight/diff-highlight | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/contrib/diff-highlight/diff-highlight b/contrib/diff-highlight/diff-highlight
index c4404d4..69a652e 100755
--- a/contrib/diff-highlight/diff-highlight
+++ b/contrib/diff-highlight/diff-highlight
@@ -14,6 +14,10 @@ my @removed;
 my @added;
 my $in_hunk;
 
+# Some scripts may not realize that SIGPIPE is being ignored when launching the
+# pager--for instance scripts written in Python.
+$SIG{PIPE} = 'DEFAULT';
+
 while (<>) {
 	if (!$in_hunk) {
 		print;
-- 
2.0.1

```

## Jeff King, 2014-11-04 20:09

Subject: Re: [PATCH v2] diff-highlight: exit when a pipe is broken
Message-ID: <20141104200932.GA15149@peff.net>
URL: https://gitlist.dev/e/20141104200932.GA15149%40peff.net
In-Reply-To: <1415131272-89441-1-git-send-email-john@szakmeister.net>

```
On Tue, Nov 04, 2014 at 03:01:12PM -0500, John Szakmeister wrote:

> While using diff-highlight with other tools, I have discovered that Python
> ignores SIGPIPE by default.  Unfortunately, this also means that tools
> attempting to launch a pager under Python--and don't realize this is
> happening--means that the subprocess inherits this setting.  In this case, it
> means diff-highlight will be launched with SIGPIPE being ignored.  Let's work
> with those broken scripts by restoring the default SIGPIPE handler.
> 
> Signed-off-by: John Szakmeister <john@szakmeister.net>
> ---
> Incorporates feedback from Jeff King and now we just restore the default signal
> handler using the correct case of 'DEFAULT'.

Thanks, this version looks much simpler. :)

Acked-by: Jeff King <peff@peff.net>

-Peff

```

## Junio C Hamano, 2014-11-04 20:52

Subject: Re: [PATCH v2] diff-highlight: exit when a pipe is broken
Message-ID: <xmqqtx2epu1i.fsf@gitster.dls.corp.google.com>
URL: https://gitlist.dev/e/xmqqtx2epu1i.fsf%40gitster.dls.corp.google.com
In-Reply-To: <20141104200932.GA15149@peff.net>

```
Jeff King <peff@peff.net> writes:

> On Tue, Nov 04, 2014 at 03:01:12PM -0500, John Szakmeister wrote:
>
>> While using diff-highlight with other tools, I have discovered that Python
>> ignores SIGPIPE by default.  Unfortunately, this also means that tools
>> attempting to launch a pager under Python--and don't realize this is
>> happening--means that the subprocess inherits this setting.  In this case, it
>> means diff-highlight will be launched with SIGPIPE being ignored.  Let's work
>> with those broken scripts by restoring the default SIGPIPE handler.
>> 
>> Signed-off-by: John Szakmeister <john@szakmeister.net>
>> ---
>> Incorporates feedback from Jeff King and now we just restore the default signal
>> handler using the correct case of 'DEFAULT'.
>
> Thanks, this version looks much simpler. :)
>
> Acked-by: Jeff King <peff@peff.net>

Thanks, both.  The patch looks good.  Will queue.

```
