Skip to content

Commit 74b77d3

Browse files
committed
fix review idea
Signed-off-by: Manjusaka <[email protected]>
1 parent d9be40e commit 74b77d3

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

Lib/test/test_pty.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,7 @@ def test_fork(self):
231231
os._exit(2)
232232
os._exit(4)
233233
else:
234-
flags = fcntl.fcntl(master_fd, fcntl.F_GETFD)
235-
self.assertTrue(flags & fcntl.FD_CLOEXEC)
234+
self.assertFalse(os.get_inheritable(master_fd))
236235
debug("Waiting for child (%d) to finish." % pid)
237236
# In verbose mode, we have to consume the debug output from the
238237
# child or the child will block, causing this test to hang in the
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Set O_CLOEXEC for master_fd when call os.forkpty
1+
:func:``os.forkpty`` does now make the returned file descriptor non-inheritable.

Modules/posixmodule.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9060,8 +9060,11 @@ os_forkpty_impl(PyObject *module)
90609060
/* parent: release the import lock. */
90619061
PyOS_AfterFork_Parent();
90629062
/* set O_CLOEXEC on master_fd */
9063-
if (_Py_set_inheritable(master_fd, 0, NULL) < 0)
9064-
goto error;
9063+
if (_Py_set_inheritable(master_fd, 0, NULL) < 0) {
9064+
close(master_fd);
9065+
return NULL;
9066+
}
9067+
90659068
// After PyOS_AfterFork_Parent() starts the world to avoid deadlock.
90669069
if (warn_about_fork_with_threads("forkpty") < 0)
90679070
return NULL;
@@ -9071,10 +9074,6 @@ os_forkpty_impl(PyObject *module)
90719074
}
90729075

90739076
return Py_BuildValue("(Ni)", PyLong_FromPid(pid), master_fd);
9074-
error:
9075-
if (master_fd != -1)
9076-
close(master_fd);
9077-
return NULL;
90789077
}
90799078
#endif /* HAVE_FORKPTY */
90809079

0 commit comments

Comments
 (0)