summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2010-03-01 06:18:41 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2010-03-01 06:18:41 (GMT)
commit24cec9fe07a1f7e408a0ff846c6491e0cf8295c4 (patch)
tree771ec4efea43ffc13b6dfb71229ec50148a70f8b /Modules
parentc78d79ce30b8303a428f075770c8fcf44cd48a53 (diff)
downloadcpython-24cec9fe07a1f7e408a0ff846c6491e0cf8295c4.zip
cpython-24cec9fe07a1f7e408a0ff846c6491e0cf8295c4.tar.gz
cpython-24cec9fe07a1f7e408a0ff846c6491e0cf8295c4.tar.bz2
Merged revisions 78527,78550 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r78527 | gregory.p.smith | 2010-02-28 17:22:39 -0800 (Sun, 28 Feb 2010) | 4 lines Issue #7242: On Solaris 9 and earlier calling os.fork() from within a thread could raise an incorrect RuntimeError about not holding the import lock. The import lock is now reinitialized after fork. ........ r78550 | gregory.p.smith | 2010-02-28 22:01:02 -0800 (Sun, 28 Feb 2010) | 2 lines Fix test to be skipped on windows. ........
Diffstat (limited to 'Modules')
-rw-r--r--Modules/posixmodule.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 8e3f4c0..202fae5 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -3723,14 +3723,18 @@ static PyObject *
posix_fork1(PyObject *self, PyObject *noargs)
{
pid_t pid;
- int result;
+ int result = 0;
_PyImport_AcquireLock();
pid = fork1();
- result = _PyImport_ReleaseLock();
+ if (pid == 0) {
+ /* child: this clobbers and resets the import lock. */
+ PyOS_AfterFork();
+ } else {
+ /* parent: release the import lock. */
+ result = _PyImport_ReleaseLock();
+ }
if (pid == -1)
return posix_error();
- if (pid == 0)
- PyOS_AfterFork();
if (result < 0) {
/* Don't clobber the OSError if the fork failed. */
PyErr_SetString(PyExc_RuntimeError,
@@ -3752,14 +3756,18 @@ static PyObject *
posix_fork(PyObject *self, PyObject *noargs)
{
pid_t pid;
- int result;
+ int result = 0;
_PyImport_AcquireLock();
pid = fork();
- result = _PyImport_ReleaseLock();
+ if (pid == 0) {
+ /* child: this clobbers and resets the import lock. */
+ PyOS_AfterFork();
+ } else {
+ /* parent: release the import lock. */
+ result = _PyImport_ReleaseLock();
+ }
if (pid == -1)
return posix_error();
- if (pid == 0)
- PyOS_AfterFork();
if (result < 0) {
/* Don't clobber the OSError if the fork failed. */
PyErr_SetString(PyExc_RuntimeError,
@@ -3877,11 +3885,12 @@ posix_forkpty(PyObject *self, PyObject *noargs)
_PyImport_AcquireLock();
pid = forkpty(&master_fd, NULL, NULL, NULL);
+ if (pid == 0)
+ PyOS_AfterFork();
+
result = _PyImport_ReleaseLock();
if (pid == -1)
return posix_error();
- if (pid == 0)
- PyOS_AfterFork();
if (result < 0) {
/* Don't clobber the OSError if the fork failed. */
PyErr_SetString(PyExc_RuntimeError,