Patchwork [5,of,5,STABLE] crecord: avoid setting non-existing SIGTSTP signal on windows (issue5512)

login
register
mail settings
Submitter Pierre-Yves David
Date April 12, 2017, 8:41 a.m.
Message ID <cd0b74f1858c5e71a6f9.1491986480@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/20128/
State Accepted
Headers show

Comments

Pierre-Yves David - April 12, 2017, 8:41 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1491470905 -7200
#      Thu Apr 06 11:28:25 2017 +0200
# Branch stable
# Node ID cd0b74f1858c5e71a6f94c5ec195c070df6272a2
# Parent  f83025d451fa293849f819cc997bc3f8c9ce42e0
# EXP-Topic crecord-windows
# Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
#              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r cd0b74f1858c
crecord: avoid setting non-existing  SIGTSTP signal on windows (issue5512)

Windows do not have a SIGTSTP so we avoid setting the handler if the signal is
unknown.
Augie Fackler - April 12, 2017, 8:50 p.m.
On Wed, Apr 12, 2017 at 10:41:20AM +0200, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
> # Date 1491470905 -7200
> #      Thu Apr 06 11:28:25 2017 +0200
> # Branch stable
> # Node ID cd0b74f1858c5e71a6f94c5ec195c070df6272a2
> # Parent  f83025d451fa293849f819cc997bc3f8c9ce42e0
> # EXP-Topic crecord-windows
> # Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
> #              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r cd0b74f1858c
> crecord: avoid setting non-existing  SIGTSTP signal on windows (issue5512)

Since we've got both an RC and a security release landing on Monday,
I've queued these for default rather than stable, so that the security
release stays as small as possible given existing queued patches.

>
> Windows do not have a SIGTSTP so we avoid setting the handler if the signal is
> unknown.
>
> diff --git a/mercurial/crecord.py b/mercurial/crecord.py
> --- a/mercurial/crecord.py
> +++ b/mercurial/crecord.py
> @@ -473,14 +473,17 @@ def chunkselector(ui, headerlist, operat
>      """
>      ui.write(_('starting interactive selection\n'))
>      chunkselector = curseschunkselector(headerlist, ui, operation)
> -    f = signal.getsignal(signal.SIGTSTP)
> +    origsigtstp = sentinel = object()
> +    if util.safehasattr(signal, 'SIGTSTP'):
> +        origsigtstp = signal.getsignal(signal.SIGTSTP)
>      try:
>          curses.wrapper(chunkselector.main)
>          if chunkselector.initerr is not None:
>              raise error.Abort(chunkselector.initerr)
>          # ncurses does not restore signal handler for SIGTSTP
>      finally:
> -        signal.signal(signal.SIGTSTP, f)
> +        if origsigtstp is not sentinel:
> +            signal.signal(signal.SIGTSTP, origsigtstp)
>      return chunkselector.opts
>
>  def testdecorator(testfn, f):
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/crecord.py b/mercurial/crecord.py
--- a/mercurial/crecord.py
+++ b/mercurial/crecord.py
@@ -473,14 +473,17 @@  def chunkselector(ui, headerlist, operat
     """
     ui.write(_('starting interactive selection\n'))
     chunkselector = curseschunkselector(headerlist, ui, operation)
-    f = signal.getsignal(signal.SIGTSTP)
+    origsigtstp = sentinel = object()
+    if util.safehasattr(signal, 'SIGTSTP'):
+        origsigtstp = signal.getsignal(signal.SIGTSTP)
     try:
         curses.wrapper(chunkselector.main)
         if chunkselector.initerr is not None:
             raise error.Abort(chunkselector.initerr)
         # ncurses does not restore signal handler for SIGTSTP
     finally:
-        signal.signal(signal.SIGTSTP, f)
+        if origsigtstp is not sentinel:
+            signal.signal(signal.SIGTSTP, origsigtstp)
     return chunkselector.opts
 
 def testdecorator(testfn, f):