[PATCH 1 of 2] chgserver: do not ignore SIGPIPE if pager is used

Yuya Nishihara yuya at tcha.org
Tue Jun 28 09:14:28 EDT 2016


On Fri, 24 Jun 2016 17:10:17 +0100, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark at fb.com>
> # Date 1466784401 -3600
> #      Fri Jun 24 17:06:41 2016 +0100
> # Node ID f1195d649b4237400de44ac741f701aded61eb95
> # Parent  2a54cf92c773777f8a5c821c6831c945eb4131c0
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r f1195d649b42
> 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.
> 
> diff --git a/hgext/chgserver.py b/hgext/chgserver.py
> --- a/hgext/chgserver.py
> +++ b/hgext/chgserver.py
> @@ -48,6 +48,7 @@ import inspect
>  import os
>  import random
>  import re
> +import signal
>  import struct
>  import sys
>  import threading
> @@ -498,6 +499,11 @@ class chgcmdserver(commandserver.server)
>  
>          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)

We'll need to restore the original handler at cleanup() if we want to support
prefork server.


More information about the Mercurial-devel mailing list