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

Simon Farnsworth simonfar at fb.com
Thu Jan 19 14:02:08 EST 2017


# HG changeset patch
# User Simon Farnsworth <simonfar at 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.

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)
 


More information about the Mercurial-devel mailing list