]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #19752: Fix "HAVE_DEV_PTMX" implementation of os.openpty()
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 25 Nov 2013 22:19:58 +0000 (23:19 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 25 Nov 2013 22:19:58 +0000 (23:19 +0100)
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).

Modules/posixmodule.c

index ae45fc3f23a1f65e4c6f488bcd9b42de5b7132a0..2f21ceb6f7ca8e8f050be2d8a9a3815c47203b81 100644 (file)
@@ -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 */