cpython: 61aa484a3e54 (original) (raw)

--- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -1295,6 +1295,11 @@ class POSIXProcessTestCase(BaseTestCase) self.addCleanup(os.close, fds[1]) open_fds = set(fds)

p = subprocess.Popen([sys.executable, fd_status], stdout=subprocess.PIPE, close_fds=False) @@ -1313,6 +1318,19 @@ class POSIXProcessTestCase(BaseTestCase) "Some fds were left open") self.assertIn(1, remaining_fds, "Subprocess failed")

+

+ # Mac OS X Tiger (10.4) has a kernel bug: sometimes, the file # descriptor of a pipe closed in the parent process is valid in the # child process according to fstat(), but the mode of the file

--- a/Modules/_posixsubprocess.c +++ b/Modules/_posixsubprocess.c @@ -5,7 +5,26 @@ #endif #include <unistd.h> #include <fcntl.h> +#ifdef HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif +#ifdef HAVE_SYS_SYSCALL_H +#include <sys/syscall.h> +#endif +#ifdef HAVE_DIRENT_H +#include <dirent.h> +#endif +#if defined(sun) && !defined(HAVE_DIRFD) +/* Some versions of Solaris lack dirfd(). */ +# define DIRFD(dirp) ((dirp)->dd_fd) +# define HAVE_DIRFD +#else +# define DIRFD(dirp) (dirfd(dirp)) +#endif + +#define LINUX_SOLARIS_FD_DIR "/proc/self/fd" +#define BSD_OSX_FD_DIR "/dev/fd" #define POSIX_CALL(call) if ((call) == -1) goto error @@ -26,6 +45,233 @@ static int _enable_gc(PyObject gc_modul } +/ Convert ASCII to a positive int, no libc call. no overflow. -1 on error. */ +static int _pos_int_from_ascii(char *name) +{

+} + + +/* Returns 1 if there is a problem with fd_sequence, 0 otherwise. */ +static int _sanity_check_python_fd_sequence(PyObject *fd_sequence) +{

+} + + +/* Is fd found in the sorted Python Sequence? */ +static int _is_fd_in_sorted_fd_sequence(int fd, PyObject *fd_sequence) +{

+} + + +/* Close all file descriptors in the range start_fd inclusive to

+{

+} + + +#if defined(linux) && defined(HAVE_SYS_SYSCALL_H) +/* It doesn't matter if d_name has room for NAME_MAX chars; we're using this

+/* Close all open file descriptors in the range start_fd inclusive to end_fd

+{

+} + +#define _close_open_fd_range _close_open_fd_range_safe + +#else /* NOT (defined(linux) && defined(HAVE_SYS_SYSCALL_H)) / + + +/ Close all open file descriptors in the range start_fd inclusive to end_fd

+{

+#ifndef HAVE_DIRFD

+#endif

+

+#ifdef HAVE_DIRFD

+#else

+#endif

+} + +#define _close_open_fd_range _close_open_fd_range_maybe_unsafe + +#endif /* else NOT (defined(linux) && defined(HAVE_SYS_SYSCALL_H)) / + + /

{

if (cwd) POSIX_CALL(chdir(cwd)); @@ -227,7 +448,7 @@ subprocess_fork_exec(PyObject* self, PyO pid_t pid; int need_to_reenable_gc = 0; char *const *exec_array, *const *argv = NULL, *const *envp = NULL;

if (!PyArg_ParseTuple( args, "OOOOOOiiiiiiiiiiO:fork_exec", @@ -243,9 +464,12 @@ subprocess_fork_exec(PyObject* self, PyO PyErr_SetString(PyExc_ValueError, "errpipe_write must be >= 3"); return NULL; }

--- a/configure +++ b/configure @@ -6165,7 +6165,7 @@ unistd.h utime.h [](#l3.3) sys/audioio.h sys/bsdtty.h sys/epoll.h sys/event.h sys/file.h sys/loadavg.h [](#l3.4) sys/lock.h sys/mkdev.h sys/modem.h [](#l3.5) sys/param.h sys/poll.h sys/select.h sys/socket.h sys/statvfs.h sys/stat.h [](#l3.6) -sys/termio.h sys/time.h [](#l3.7) +sys/syscall.h sys/termio.h sys/time.h [](#l3.8) sys/times.h sys/types.h sys/un.h sys/utsname.h sys/wait.h pty.h libutil.h [](#l3.9) sys/resource.h netpacket/packet.h sysexits.h bluetooth.h [](#l3.10) bluetooth/bluetooth.h linux/tipc.h spawn.h util.h

--- a/configure.in +++ b/configure.in @@ -1341,7 +1341,7 @@ unistd.h utime.h [](#l4.3) sys/audioio.h sys/bsdtty.h sys/epoll.h sys/event.h sys/file.h sys/loadavg.h [](#l4.4) sys/lock.h sys/mkdev.h sys/modem.h [](#l4.5) sys/param.h sys/poll.h sys/select.h sys/socket.h sys/statvfs.h sys/stat.h [](#l4.6) -sys/termio.h sys/time.h [](#l4.7) +sys/syscall.h sys/termio.h sys/time.h [](#l4.8) sys/times.h sys/types.h sys/un.h sys/utsname.h sys/wait.h pty.h libutil.h [](#l4.9) sys/resource.h netpacket/packet.h sysexits.h bluetooth.h [](#l4.10) bluetooth/bluetooth.h linux/tipc.h spawn.h util.h)

--- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -789,6 +789,9 @@ /* Define to 1 if you have the <sys/stat.h> header file. / #undef HAVE_SYS_STAT_H +/ Define to 1 if you have the <sys/syscall.h> header file. / +#undef HAVE_SYS_SYSCALL_H + / Define to 1 if you have the <sys/termio.h> header file. */ #undef HAVE_SYS_TERMIO_H