summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2010-03-01 04:40:36 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2010-03-01 04:40:36 (GMT)
commitc21d0cb6cf1c32158a37772545fb71e730ab1323 (patch)
tree834c4f78660a6d3d0a92153bc7027439b386363d /Modules/posixmodule.c
parent56f1682a4462559b735c01c6cb8c06fd1afdc11b (diff)
downloadcpython-c21d0cb6cf1c32158a37772545fb71e730ab1323.zip
cpython-c21d0cb6cf1c32158a37772545fb71e730ab1323.tar.gz
cpython-c21d0cb6cf1c32158a37772545fb71e730ab1323.tar.bz2
Merged revisions 78527,78531 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. ........ r78531 | gregory.p.smith | 2010-02-28 18:31:33 -0800 (Sun, 28 Feb 2010) | 2 lines Fix for r78527. It left out updating forkpty. ........
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c36
1 files changed, 24 insertions, 12 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 616722f..50ef803 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -3632,14 +3632,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,
@@ -3661,14 +3665,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,
@@ -3777,16 +3785,20 @@ To both, return fd of newly opened pseudo-terminal.\n");
static PyObject *
posix_forkpty(PyObject *self, PyObject *noargs)
{
- int master_fd = -1, result;
+ int master_fd = -1, result = 0;
pid_t pid;
_PyImport_AcquireLock();
pid = forkpty(&master_fd, NULL, NULL, NULL);
- 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,