Mercurial > cpython-lru_cache-weakref
diff Modules/selectmodule.c @ 85420:ef889c3d5dc6
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().
| author | Victor Stinner <victor.stinner@gmail.com> |
|---|---|
| date | Wed, 28 Aug 2013 00:53:59 +0200 |
| parents | 8345fb616cbd |
| children | b4bc10514174 |
line wrap: on
line diff
--- a/Modules/selectmodule.c Tue Aug 27 20:17:03 2013 +0300 +++ b/Modules/selectmodule.c Wed Aug 28 00:53:59 2013 +0200 @@ -1004,7 +1004,7 @@ */ 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 @@ 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 @@ 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 @@ 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,
