summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-11-25 22:19:58 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-11-25 22:19:58 (GMT)
commit000de53624d7904d48caab7b315d2a52938fdb1d (patch)
tree3dda0c3f606891a3bf42d3903f5dc0f3d363aed4 /Modules/posixmodule.c
parentb4a04fb7e6407d5107dba9aa2770554cc66de9bb (diff)
downloadcpython-000de53624d7904d48caab7b315d2a52938fdb1d.zip
cpython-000de53624d7904d48caab7b315d2a52938fdb1d.tar.gz
cpython-000de53624d7904d48caab7b315d2a52938fdb1d.tar.bz2
Issue #19752: Fix "HAVE_DEV_PTMX" implementation of os.openpty()
Regression introduced by the implementation of the PEP 446 (non-inheritable file descriptors by default). master_fd must be set non-inheritable after the creation of the slave_fd, otherwise grantpt(master_fd) fails with EPERM (errno 13).
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index ae45fc3..2f21ceb 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -6014,7 +6014,7 @@ posix_openpty(PyObject *self, PyObject *noargs)
goto posix_error;
#else
- master_fd = _Py_open(DEV_PTY_FILE, O_RDWR | O_NOCTTY); /* open master */
+ master_fd = open(DEV_PTY_FILE, O_RDWR | O_NOCTTY); /* open master */
if (master_fd < 0)
goto posix_error;
@@ -6041,6 +6041,10 @@ posix_openpty(PyObject *self, PyObject *noargs)
slave_fd = _Py_open(slave_name, O_RDWR | O_NOCTTY); /* open slave */
if (slave_fd < 0)
goto posix_error;
+
+ if (_Py_set_inheritable(master_fd, 0, NULL) < 0)
+ goto posix_error;
+
#if !defined(__CYGWIN__) && !defined(HAVE_DEV_PTC)
ioctl(slave_fd, I_PUSH, "ptem"); /* push ptem */
ioctl(slave_fd, I_PUSH, "ldterm"); /* push ldterm */