Patchwork [2,of,5] pager: don't terminate with extreme prejudice on SIGPIPE (BC)

login
register
mail settings
Submitter Simon Farnsworth
Date Jan. 19, 2017, 7:02 p.m.
Message ID <d444a9f4d468b7a0705d.1484852528@devvm022.lla2.facebook.com>
Download mbox | patch
Permalink /patch/18262/
State Deferred
Headers show

Comments

Simon Farnsworth - Jan. 19, 2017, 7:02 p.m.
# HG changeset patch
# User Simon Farnsworth <simonfar@fb.com>
# Date 1484836838 28800
#      Thu Jan 19 06:40:38 2017 -0800
# Node ID d444a9f4d468b7a0705d48b2f4f84c7bd44b6c74
# Parent  76123ae2e0ccaa58db3d4fc26b75b7251e13ad16
pager: don't terminate with extreme prejudice on SIGPIPE (BC)

The default SIGPIPE handler causes Mercurial to exit immediately, without
running any Python cleanup code (except and finally blocks, atexit handlers
etc). This creates problems if you want to do something at exit.

If we need a different exit code for broken pipe from pager, then we should
code that ourselves in Python; this appears to have been cargo-culted from
the fork implementation of pager that's no longer used, where it was needed
to stop Broken Pipe errors appearing on the user's terminal.

Patch

diff --git a/hgext/pager.py b/hgext/pager.py
--- a/hgext/pager.py
+++ b/hgext/pager.py
@@ -92,7 +92,7 @@ 
     stderrfd = os.dup(util.stderr.fileno())
 
     os.dup2(pager.stdin.fileno(), util.stdout.fileno())
-    if ui._isatty(util.stderr):
+    if False and ui._isatty(util.stderr):
         os.dup2(pager.stdin.fileno(), util.stderr.fileno())
 
     @atexit.register
@@ -149,8 +149,6 @@ 
         if usepager:
             ui.setconfig('ui', 'formatted', ui.formatted(), 'pager')
             ui.setconfig('ui', 'interactive', False, 'pager')
-            if util.safehasattr(signal, "SIGPIPE"):
-                signal.signal(signal.SIGPIPE, signal.SIG_DFL)
             ui._runpager(p)
         return orig(ui, options, cmd, cmdfunc)