]> granicus.if.org Git - python/commitdiff
This fix (across 4 files in 3 directories) solves a subtle problem with
authorGuido van Rossum <guido@python.org>
Fri, 14 Nov 1997 22:24:28 +0000 (22:24 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 14 Nov 1997 22:24:28 +0000 (22:24 +0000)
signal handlers in a fork()ed child process when Python is compiled with
thread support.  The bug was reported by Scott <scott@chronis.icgroup.com>.

What happens is that after a fork(), the variables used by the signal
module to determine whether this is the main thread or not are bogus,
and it decides that no thread is the main thread, so no signals will
be delivered.

The solution is the addition of PyOS_AfterFork(), which fixes the signal
module's variables.  A dummy version of the function is present in the
intrcheck.c source file which is linked when the signal module is not
used.

Include/intrcheck.h
Modules/posixmodule.c
Modules/signalmodule.c
Parser/intrcheck.c

index f9658e28b1464e26b7890e87d48f1342527281cc..85660516900e5231167331a8da6a070042bf4d15 100644 (file)
@@ -37,6 +37,7 @@ PERFORMANCE OF THIS SOFTWARE.
 
 extern int PyOS_InterruptOccurred Py_PROTO((void));
 extern void PyOS_InitInterrupts Py_PROTO((void));
+void PyOS_AfterFork Py_PROTO((void));
 
 #ifdef __cplusplus
 }
index e06827aa720d64748ff48504c3949362691679be..58111efda5eb3cc450c8e309a95cfcc2d71f944b 100644 (file)
@@ -1082,6 +1082,7 @@ posix_fork(self, args)
        pid = fork();
        if (pid == -1)
                return posix_error();
+       PyOS_AfterFork();
        return PyInt_FromLong((long)pid);
 }
 #endif
index e8154925278b4b6c9217b253d199a0c535df087c..e91c3cb6f6054dfa0d273ad6477122ad21c9ce60 100644 (file)
@@ -613,3 +613,12 @@ PyOS_InterruptOccurred()
        }
        return 0;
 }
+
+void
+PyOS_AfterFork()
+{
+#ifdef WITH_THREAD
+       main_thread = get_thread_ident();
+       main_pid = getpid();
+#endif
+}
index a2a31452bb42454794be613afb616364946a7bec..7fe6205f444b9ffef7dc5fa8d8ed5c275c255eea 100644 (file)
@@ -219,3 +219,8 @@ PyOS_InterruptOccurred()
 }
 
 #endif /* !OK */
+
+void
+PyOS_AfterFork()
+{
+}