diff options
Diffstat (limited to 'Modules/posixmodule.c')
| -rw-r--r-- | Modules/posixmodule.c | 29 |
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, |
