changeset 29428:247ea0dfdb94

chgserver: do not ignore SIGPIPE if pager is used We rely on SIGPIPE to exit when the pager exits. And Python ignores SIGPIPE by default. Explicitly set SIGPIPE handler to SIG_DFL (terminate) just like pager.py.
author Jun Wu <quark@fb.com>
date Fri, 24 Jun 2016 17:06:41 +0100
parents 33a6b750b5b9
children cf99de051385
files hgext/chgserver.py
diffstat 1 files changed, 6 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/chgserver.py	Fri Jun 24 11:12:41 2016 -0700
+++ b/hgext/chgserver.py	Fri Jun 24 17:06:41 2016 +0100
@@ -48,6 +48,7 @@
 import os
 import random
 import re
+import signal
 import struct
 import sys
 import threading
@@ -498,6 +499,11 @@
 
         pagercmd = _setuppagercmd(self.ui, options, cmd)
         if pagercmd:
+            # Python's SIGPIPE is SIG_IGN by default. change to SIG_DFL so
+            # we can exit if the pipe to the pager is closed
+            if util.safehasattr(signal, 'SIGPIPE') and \
+                    signal.getsignal(signal.SIGPIPE) == signal.SIG_IGN:
+                signal.signal(signal.SIGPIPE, signal.SIG_DFL)
             self.cresult.write(pagercmd)
         else:
             self.cresult.write('\0')