Patchwork [2,of,3] worker: fix a race in SIGINT handling

login
register
mail settings
Submitter Bryan O'Sullivan
Date Feb. 19, 2013, 6:29 p.m.
Message ID <9ef52f0a93a0cba93974.1361298554@australite.local>
Download mbox | patch
Permalink /patch/1030/
State Superseded
Headers show

Comments

Bryan O'Sullivan - Feb. 19, 2013, 6:29 p.m.
# HG changeset patch
# User Bryan O'Sullivan <bryano@fb.com>
# Date 1361297550 28800
# Node ID 9ef52f0a93a0cba939742743ff59e4c2a2463fab
# Parent  aa2394d75dcc1fb33f3f548013874acdfbaf845f
worker: fix a race in SIGINT handling

This is almost impossible to trigger due to the tiny time window involved.

Patch

diff --git a/mercurial/worker.py b/mercurial/worker.py
--- a/mercurial/worker.py
+++ b/mercurial/worker.py
@@ -75,9 +75,12 @@  def worker(ui, costperarg, func, statica
 def _posixworker(ui, func, staticargs, args):
     rfd, wfd = os.pipe()
     workers = _numworkers(ui)
+    oldhandler = signal.getsignal(signal.SIGINT)
+    signal.signal(signal.SIGINT, signal.SIG_IGN)
     for pargs in partition(args, workers):
         pid = os.fork()
         if pid == 0:
+            signal.signal(signal.SIGINT, oldhandler)
             try:
                 os.close(rfd)
                 for i, item in func(*(staticargs + (pargs,))):
@@ -87,8 +90,6 @@  def _posixworker(ui, func, staticargs, a
                 os._exit(255)
     os.close(wfd)
     fp = os.fdopen(rfd, 'rb', 0)
-    oldhandler = signal.getsignal(signal.SIGINT)
-    signal.signal(signal.SIGINT, signal.SIG_IGN)
     def cleanup():
         # python 2.4 is too dumb for try/yield/finally
         signal.signal(signal.SIGINT, oldhandler)