summaryrefslogtreecommitdiffstats
path: root/Modules/selectmodule.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-08-27 22:53:59 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-08-27 22:53:59 (GMT)
commitdaf455554bc21b6b5df0a016ab5fa639d36cc595 (patch)
tree216f52f9f6d9aed0406b2ce2574e5a02aa93e327 /Modules/selectmodule.c
parent46e1ce214b5711e8dae63a1b5a0a7aafb371baf0 (diff)
downloadcpython-daf455554bc21b6b5df0a016ab5fa639d36cc595.zip
cpython-daf455554bc21b6b5df0a016ab5fa639d36cc595.tar.gz
cpython-daf455554bc21b6b5df0a016ab5fa639d36cc595.tar.bz2
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
are now created non-inheritable; add functions os.get/set_inheritable(), os.get/set_handle_inheritable() and socket.socket.get/set_inheritable().
Diffstat (limited to 'Modules/selectmodule.c')
-rw-r--r--Modules/selectmodule.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index 5da0d92..0ff09b4 100644
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -1004,7 +1004,7 @@ newDevPollObject(void)
*/
limit_result = getrlimit(RLIMIT_NOFILE, &limit);
if (limit_result != -1)
- fd_devpoll = open("/dev/poll", O_RDWR);
+ fd_devpoll = _Py_open("/dev/poll", O_RDWR);
Py_END_ALLOW_THREADS
if (limit_result == -1) {
@@ -1194,6 +1194,7 @@ newPyEpoll_Object(PyTypeObject *type, int sizehint, int flags, SOCKET fd)
if (fd == -1) {
Py_BEGIN_ALLOW_THREADS
#ifdef HAVE_EPOLL_CREATE1
+ flags |= EPOLL_CLOEXEC;
if (flags)
self->epfd = epoll_create1(flags);
else
@@ -1209,6 +1210,14 @@ newPyEpoll_Object(PyTypeObject *type, int sizehint, int flags, SOCKET fd)
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
+
+#ifndef HAVE_EPOLL_CREATE1
+ if (_Py_set_inheritable(self->epfd, 0, NULL) < 0) {
+ Py_DECREF(self);
+ return NULL;
+ }
+#endif
+
return (PyObject *)self;
}
@@ -1896,13 +1905,19 @@ newKqueue_Object(PyTypeObject *type, SOCKET fd)
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
+
+ if (fd == -1) {
+ if (_Py_set_inheritable(self->kqfd, 0, NULL) < 0) {
+ Py_DECREF(self);
+ return NULL;
+ }
+ }
return (PyObject *)self;
}
static PyObject *
kqueue_queue_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
-
if ((args != NULL && PyObject_Size(args)) ||
(kwds != NULL && PyObject_Size(kwds))) {
PyErr_SetString(PyExc_ValueError,