]> granicus.if.org Git - python/commitdiff
Fixes issue #9535: Fix pending signals that have been received but not yet
authorGregory P. Smith <greg@krypto.org>
Sun, 11 Nov 2012 04:38:17 +0000 (20:38 -0800)
committerGregory P. Smith <greg@krypto.org>
Sun, 11 Nov 2012 04:38:17 +0000 (20:38 -0800)
handled by Python to not persist after os.fork() in the child process.

Misc/NEWS
Modules/signalmodule.c

index a4a4105abdf85cb9cda0b0ba04183cf0042ac48d..a670e2026c44bc445c8b78e13dcb9f4df568211f 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -9,6 +9,9 @@ What's New in Python 2.7.4
 Core and Builtins
 -----------------
 
+- Issue #9535: Fix pending signals that have been received but not yet
+  handled by Python to not persist after os.fork() in the child process.
+
 - Issue #15001: fix segfault on "del sys.modules['__main__']". Patch by Victor
   Stinner.
 
index 908c2ee994044c0f968b52ba78154b6dedefe32b..f706a8fd8f359adc880929dd1fad3d2859680126 100644 (file)
@@ -972,9 +972,25 @@ PyOS_InterruptOccurred(void)
     return 0;
 }
 
+static void
+_clear_pending_signals(void)
+{
+    int i;
+    if (!is_tripped)
+        return;
+    is_tripped = 0;
+    for (i = 1; i < NSIG; ++i) {
+        Handlers[i].tripped = 0;
+    }
+}
+
 void
 PyOS_AfterFork(void)
 {
+    /* Clear the signal flags after forking so that they aren't handled
+     * in both processes if they came in just before the fork() but before
+     * the interpreter had an opportunity to call the handlers.  issue9535. */
+    _clear_pending_signals();
 #ifdef WITH_THREAD
     /* PyThread_ReInitTLS() must be called early, to make sure that the TLS API
      * can be called safely. */