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

login
register
mail settings
Submitter Bryan O'Sullivan
Date Feb. 19, 2013, 8:54 p.m.
Message ID <e0bdbbb4e62ae8e1b588.1361307245@australite.thefacebook.com>
Download mbox | patch
Permalink /patch/1034/
State Accepted
Commit 86524a70c0f6272917dc03ed0b258917c81f4419
Headers show

Comments

Bryan O'Sullivan - Feb. 19, 2013, 8:54 p.m.
# HG changeset patch
# User Bryan O'Sullivan <bryano@fb.com>
# Date 1361307231 28800
# Node ID e0bdbbb4e62ae8e1b588d39f514b59557fe75cfc
# Parent  bd5bb50f9f1660152459d13b921e599b8af96b13
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)