summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-11-14 22:24:28 (GMT)
committerGuido van Rossum <guido@python.org>1997-11-14 22:24:28 (GMT)
commit359bcaa539d9bbb2b008b5fd0a76c758b489bed5 (patch)
treee6c5cb83090ef2a2cffcbb18f0ec5db28111a960 /Modules
parentc9fd600640229af8381f207b7d9224ba86db7206 (diff)
downloadcpython-359bcaa539d9bbb2b008b5fd0a76c758b489bed5.zip
cpython-359bcaa539d9bbb2b008b5fd0a76c758b489bed5.tar.gz
cpython-359bcaa539d9bbb2b008b5fd0a76c758b489bed5.tar.bz2
This fix (across 4 files in 3 directories) solves a subtle problem with
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.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/posixmodule.c1
-rw-r--r--Modules/signalmodule.c9
2 files changed, 10 insertions, 0 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index e06827a..58111ef 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -1082,6 +1082,7 @@ posix_fork(self, args)
pid = fork();
if (pid == -1)
return posix_error();
+ PyOS_AfterFork();
return PyInt_FromLong((long)pid);
}
#endif
diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c
index e815492..e91c3cb 100644
--- a/Modules/signalmodule.c
+++ b/Modules/signalmodule.c
@@ -613,3 +613,12 @@ PyOS_InterruptOccurred()
}
return 0;
}
+
+void
+PyOS_AfterFork()
+{
+#ifdef WITH_THREAD
+ main_thread = get_thread_ident();
+ main_pid = getpid();
+#endif
+}