diff options
author | Gregory P. Smith <greg@mad-scientist.com> | 2011-01-02 20:52:48 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@mad-scientist.com> | 2011-01-02 20:52:48 (GMT) |
commit | abcfcba61c0825454f872131bb6fe4943d3a1ee7 (patch) | |
tree | 1c5ea4a60842d2d853812ab82e98c7f06d9c813c /Modules/_posixsubprocess.c | |
parent | e2dc0822941fd81e9db017f85a8475a26c00f952 (diff) | |
download | cpython-abcfcba61c0825454f872131bb6fe4943d3a1ee7.zip cpython-abcfcba61c0825454f872131bb6fe4943d3a1ee7.tar.gz cpython-abcfcba61c0825454f872131bb6fe4943d3a1ee7.tar.bz2 |
issue10802: fallback to pipe+fcntl when the pipe2 syscall fails with errno ENOSYS.
Diffstat (limited to 'Modules/_posixsubprocess.c')
-rw-r--r-- | Modules/_posixsubprocess.c | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c index d2f8d45..a175d42 100644 --- a/Modules/_posixsubprocess.c +++ b/Modules/_posixsubprocess.c @@ -415,27 +415,39 @@ subprocess_cloexec_pipe(PyObject *self, PyObject *noargs) Py_BEGIN_ALLOW_THREADS res = pipe2(fds, O_CLOEXEC); Py_END_ALLOW_THREADS -#else - /* We hold the GIL which offers some protection from other code calling - * fork() before the CLOEXEC flags have been set but we can't guarantee - * anything without pipe2(). */ - long oldflags; + if (res != 0 && errno == ENOSYS) + { + if (PyErr_WarnEx( + PyExc_RuntimeWarning, + "pipe2 set errno ENOSYS; falling " + "back to non-atomic pipe+fcntl.", 1) != 0) { + return NULL; + } + { +#endif + /* We hold the GIL which offers some protection from other code calling + * fork() before the CLOEXEC flags have been set but we can't guarantee + * anything without pipe2(). */ + long oldflags; - res = pipe(fds); + res = pipe(fds); - if (res == 0) { - oldflags = fcntl(fds[0], F_GETFD, 0); - if (oldflags < 0) res = oldflags; - } - if (res == 0) - res = fcntl(fds[0], F_SETFD, oldflags | FD_CLOEXEC); + if (res == 0) { + oldflags = fcntl(fds[0], F_GETFD, 0); + if (oldflags < 0) res = oldflags; + } + if (res == 0) + res = fcntl(fds[0], F_SETFD, oldflags | FD_CLOEXEC); - if (res == 0) { - oldflags = fcntl(fds[1], F_GETFD, 0); - if (oldflags < 0) res = oldflags; + if (res == 0) { + oldflags = fcntl(fds[1], F_GETFD, 0); + if (oldflags < 0) res = oldflags; + } + if (res == 0) + res = fcntl(fds[1], F_SETFD, oldflags | FD_CLOEXEC); +#ifdef HAVE_PIPE2 + } } - if (res == 0) - res = fcntl(fds[1], F_SETFD, oldflags | FD_CLOEXEC); #endif if (res != 0) return PyErr_SetFromErrno(PyExc_OSError); |