[PATCH] pager: exit cleanly on SIGPIPE (BC)

Simon Farnsworth simonfar at fb.com
Wed Feb 8 15:47:39 UTC 2017


# HG changeset patch
# User Simon Farnsworth <simonfar at fb.com>
# Date 1486568650 28800
#      Wed Feb 08 07:44:10 2017 -0800
# Node ID d50cda2a403786836d1f0d5c99401599dc4f43ec
# Parent  1f51b4658f21bbb797e922d155c1046eddccf91d
pager: exit cleanly on SIGPIPE (BC)

Changeset aaa751585325 removes SIGPIPE handling completely. This is wrong,
as it means that Mercurial does not exit when the pager does. Instead, raise
SignalInterrupt when SIGPIPE happens with a pager attached, to trigger the
normal exit path.

This will cause "killed!" to be printed to stderr (hence the BC warning),
but in the normal pager use case (where the pager gets both stderr and
stdout), this messsage is lost as we only get SIGPIPE when the pager quits.

diff --git a/hgext/pager.py b/hgext/pager.py
--- a/hgext/pager.py
+++ b/hgext/pager.py
@@ -72,6 +72,7 @@
     commands,
     dispatch,
     encoding,
+    error,
     extensions,
     util,
     )
@@ -114,6 +115,9 @@
         os.dup2(stderrfd, util.stderr.fileno())
         pager.wait()
 
+def catchterm(*args):
+    raise error.SignalInterrupt
+
 def uisetup(ui):
     class pagerui(ui.__class__):
         def _runpager(self, pagercmd):
@@ -153,6 +157,8 @@
         if usepager:
             ui.setconfig('ui', 'formatted', ui.formatted(), 'pager')
             ui.setconfig('ui', 'interactive', False, 'pager')
+            if util.safehasattr(signal, "SIGPIPE"):
+                signal.signal(signal.SIGPIPE, catchterm)
             ui._runpager(p)
         return orig(ui, options, cmd, cmdfunc)
 


More information about the Mercurial-devel mailing list