From patchwork Thu Jan 19 19:02:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [2, of, 5] pager: don't terminate with extreme prejudice on SIGPIPE (BC) From: Simon Farnsworth X-Patchwork-Id: 18262 Message-Id: To: Date: Thu, 19 Jan 2017 11:02:08 -0800 # HG changeset patch # User Simon Farnsworth # 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)