git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] diff-highlight: exit when a pipe is broken
@ 2014-10-31 11:04 John Szakmeister
  2014-11-01  4:04 ` Jeff King
  0 siblings, 1 reply; 3+ messages in thread
From: John Szakmeister @ 2014-10-31 11:04 UTC (permalink / raw)
  To: git; +Cc: John Szakmeister

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 explicitly setting up a SIGPIPE handler and exiting
the process.

Signed-off-by: John Szakmeister <john@szakmeister.net>
---
 contrib/diff-highlight/diff-highlight | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/contrib/diff-highlight/diff-highlight b/contrib/diff-highlight/diff-highlight
index c4404d4..dfcc35a 100755
--- a/contrib/diff-highlight/diff-highlight
+++ b/contrib/diff-highlight/diff-highlight
@@ -14,6 +14,15 @@ 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.  Setting $SIG{PIPE} = 'DEFAULT'
+# doesn't work in these instances, so we install our own signal handler instead.
+sub pipe_handler {
+    exit(0);
+}
+
+$SIG{PIPE} = \&pipe_handler;
+
 while (<>) {
 	if (!$in_hunk) {
 		print;
-- 
2.0.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-11-04 19:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-31 11:04 [PATCH] diff-highlight: exit when a pipe is broken John Szakmeister
2014-11-01  4:04 ` Jeff King
2014-11-04 19:43   ` John Szakmeister

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 NNTP newsgroup(s).