]> granicus.if.org Git - python/commitdiff
Fix bug #392, reported by Jonathan Giddy <jon@dstc.edu.au>:
authorFred Drake <fdrake@acm.org>
Thu, 6 Jul 2000 19:42:19 +0000 (19:42 +0000)
committerFred Drake <fdrake@acm.org>
Thu, 6 Jul 2000 19:42:19 +0000 (19:42 +0000)
In posixmodule.c:posix_fork, the function PyOS_AfterFork is called for
both the parent and the child, despite the docs stating that it should
be called in the new (child) process.

This causes problems in the parent since the forking thread becomes the
main thread according to the signal module.

Calling PyOS_AfterFork() only in the child fixes this.  Changed for both
fork() and forkpty().

Modules/posixmodule.c

index d85b91cc0b49753d1c47cd1f74bb2ff2f70eacd5..eea797e940d2ec9070386af0bba7de84f9f74b0b 100644 (file)
@@ -1755,7 +1755,8 @@ posix_fork(self, args)
        pid = fork();
        if (pid == -1)
                return posix_error();
-       PyOS_AfterFork();
+       if (pid == 0)
+               PyOS_AfterFork();
        return PyInt_FromLong((long)pid);
 }
 #endif
@@ -1814,7 +1815,8 @@ posix_forkpty(self, args)
        pid = forkpty(&master_fd, NULL, NULL, NULL);
        if (pid == -1)
                return posix_error();
-       PyOS_AfterFork();
+       if (pid == 0)
+               PyOS_AfterFork();
        return Py_BuildValue("(ii)", pid, master_fd);
 }
 #endif