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.
........
This commit is contained in:
Gregory P. Smith 2010-03-01 04:40:36 +00:00
parent 56f1682a44
commit c21d0cb6cf
4 changed files with 76 additions and 18 deletions

View file

@ -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,