blob: 5007a39bc2443df13143fef029c6f788f54e580a [file] [log] [blame]
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +00001/* Authors: Gregory P. Smith & Jeffrey Yasskin */
2#include "Python.h"
Victor Stinner5572ba72011-05-26 14:10:08 +02003#if defined(HAVE_PIPE2) && !defined(_GNU_SOURCE)
4# define _GNU_SOURCE
Gregory P. Smith51ee2702010-12-13 07:59:39 +00005#endif
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +00006#include <unistd.h>
Gregory P. Smith51ee2702010-12-13 07:59:39 +00007#include <fcntl.h>
Gregory P. Smith8facece2012-01-21 14:01:08 -08008#ifdef HAVE_SYS_TYPES_H
9#include <sys/types.h>
10#endif
Gregory P. Smith4842efc2012-01-21 21:01:24 -080011#if defined(HAVE_SYS_STAT_H) && defined(__FreeBSD__)
12#include <sys/stat.h>
13#endif
Gregory P. Smith8facece2012-01-21 14:01:08 -080014#ifdef HAVE_SYS_SYSCALL_H
15#include <sys/syscall.h>
16#endif
Gregory P. Smithf9681772015-04-25 23:43:34 -070017#if defined(HAVE_SYS_RESOURCE_H)
18#include <sys/resource.h>
19#endif
Gregory P. Smith8facece2012-01-21 14:01:08 -080020#ifdef HAVE_DIRENT_H
21#include <dirent.h>
22#endif
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +000023
Xavier de Gayec716f182016-06-15 11:35:29 +020024#if defined(__ANDROID__) && __ANDROID_API__ < 21 && !defined(SYS_getdents64)
Gregory P. Smithefeb9da2014-04-14 13:31:21 -070025# include <sys/linux-syscalls.h>
26# define SYS_getdents64 __NR_getdents64
27#endif
28
Gregory P. Smithe3f78482012-01-21 15:16:17 -080029#if defined(sun)
30/* readdir64 is used to work around Solaris 9 bug 6395699. */
31# define readdir readdir64
32# define dirent dirent64
33# if !defined(HAVE_DIRFD)
Gregory P. Smith8facece2012-01-21 14:01:08 -080034/* Some versions of Solaris lack dirfd(). */
Gregory P. Smithe9b7cab2012-01-21 15:19:11 -080035# define dirfd(dirp) ((dirp)->dd_fd)
Gregory P. Smithe3f78482012-01-21 15:16:17 -080036# define HAVE_DIRFD
Gregory P. Smithe3f78482012-01-21 15:16:17 -080037# endif
Gregory P. Smith8facece2012-01-21 14:01:08 -080038#endif
39
Gregory P. Smith4842efc2012-01-21 21:01:24 -080040#if defined(__FreeBSD__) || (defined(__APPLE__) && defined(__MACH__))
41# define FD_DIR "/dev/fd"
42#else
43# define FD_DIR "/proc/self/fd"
44#endif
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +000045
Victor Stinnerdaf45552013-08-28 00:53:59 +020046#define POSIX_CALL(call) do { if ((call) == -1) goto error; } while (0)
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +000047
48
Martin Panterafdd5132015-11-30 02:21:41 +000049/* If gc was disabled, call gc.enable(). Return 0 on success. */
Benjamin Peterson91eef982012-01-22 20:04:46 -050050static int
Martin Panterafdd5132015-11-30 02:21:41 +000051_enable_gc(int need_to_reenable_gc, PyObject *gc_module)
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +000052{
53 PyObject *result;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +020054 _Py_IDENTIFIER(enable);
Martin Panterafdd5132015-11-30 02:21:41 +000055 PyObject *exctype, *val, *tb;
Martin v. Löwisafe55bb2011-10-09 10:38:36 +020056
Martin Panterafdd5132015-11-30 02:21:41 +000057 if (need_to_reenable_gc) {
58 PyErr_Fetch(&exctype, &val, &tb);
59 result = _PyObject_CallMethodId(gc_module, &PyId_enable, NULL);
60 if (exctype != NULL) {
61 PyErr_Restore(exctype, val, tb);
62 }
63 if (result == NULL) {
64 return 1;
65 }
66 Py_DECREF(result);
67 }
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +000068 return 0;
69}
70
71
Gregory P. Smith8facece2012-01-21 14:01:08 -080072/* Convert ASCII to a positive int, no libc call. no overflow. -1 on error. */
Benjamin Peterson91eef982012-01-22 20:04:46 -050073static int
Serhiy Storchakaef1585e2015-12-25 20:01:53 +020074_pos_int_from_ascii(const char *name)
Gregory P. Smith8facece2012-01-21 14:01:08 -080075{
76 int num = 0;
77 while (*name >= '0' && *name <= '9') {
78 num = num * 10 + (*name - '0');
79 ++name;
80 }
81 if (*name)
82 return -1; /* Non digit found, not a number. */
83 return num;
84}
85
86
Gregory P. Smith4842efc2012-01-21 21:01:24 -080087#if defined(__FreeBSD__)
88/* When /dev/fd isn't mounted it is often a static directory populated
89 * with 0 1 2 or entries for 0 .. 63 on FreeBSD, NetBSD and OpenBSD.
90 * NetBSD and OpenBSD have a /proc fs available (though not necessarily
91 * mounted) and do not have fdescfs for /dev/fd. MacOS X has a devfs
92 * that properly supports /dev/fd.
93 */
Benjamin Peterson91eef982012-01-22 20:04:46 -050094static int
Ross Lagerwall7f4fdb22012-03-07 20:06:33 +020095_is_fdescfs_mounted_on_dev_fd(void)
Gregory P. Smith4842efc2012-01-21 21:01:24 -080096{
97 struct stat dev_stat;
98 struct stat dev_fd_stat;
99 if (stat("/dev", &dev_stat) != 0)
100 return 0;
101 if (stat(FD_DIR, &dev_fd_stat) != 0)
Victor Stinnerdaf45552013-08-28 00:53:59 +0200102 return 0;
Gregory P. Smith4842efc2012-01-21 21:01:24 -0800103 if (dev_stat.st_dev == dev_fd_stat.st_dev)
104 return 0; /* / == /dev == /dev/fd means it is static. #fail */
105 return 1;
106}
107#endif
108
109
Gregory P. Smith8facece2012-01-21 14:01:08 -0800110/* Returns 1 if there is a problem with fd_sequence, 0 otherwise. */
Benjamin Peterson91eef982012-01-22 20:04:46 -0500111static int
112_sanity_check_python_fd_sequence(PyObject *fd_sequence)
Gregory P. Smith8facece2012-01-21 14:01:08 -0800113{
114 Py_ssize_t seq_idx, seq_len = PySequence_Length(fd_sequence);
115 long prev_fd = -1;
116 for (seq_idx = 0; seq_idx < seq_len; ++seq_idx) {
117 PyObject* py_fd = PySequence_Fast_GET_ITEM(fd_sequence, seq_idx);
118 long iter_fd = PyLong_AsLong(py_fd);
Gregory P. Smithd0a5b1c2015-11-15 21:15:26 -0800119 if (iter_fd < 0 || iter_fd <= prev_fd || iter_fd > INT_MAX) {
Gregory P. Smith8facece2012-01-21 14:01:08 -0800120 /* Negative, overflow, not a Long, unsorted, too big for a fd. */
121 return 1;
122 }
Gregory P. Smithd0a5b1c2015-11-15 21:15:26 -0800123 prev_fd = iter_fd;
Gregory P. Smith8facece2012-01-21 14:01:08 -0800124 }
125 return 0;
126}
127
128
129/* Is fd found in the sorted Python Sequence? */
Benjamin Peterson91eef982012-01-22 20:04:46 -0500130static int
131_is_fd_in_sorted_fd_sequence(int fd, PyObject *fd_sequence)
Gregory P. Smith8facece2012-01-21 14:01:08 -0800132{
133 /* Binary search. */
134 Py_ssize_t search_min = 0;
135 Py_ssize_t search_max = PySequence_Length(fd_sequence) - 1;
136 if (search_max < 0)
137 return 0;
138 do {
139 long middle = (search_min + search_max) / 2;
140 long middle_fd = PyLong_AsLong(
141 PySequence_Fast_GET_ITEM(fd_sequence, middle));
142 if (fd == middle_fd)
143 return 1;
144 if (fd > middle_fd)
145 search_min = middle + 1;
146 else
147 search_max = middle - 1;
148 } while (search_min <= search_max);
149 return 0;
150}
151
Victor Stinnerdaf45552013-08-28 00:53:59 +0200152static int
153make_inheritable(PyObject *py_fds_to_keep, int errpipe_write)
154{
155 Py_ssize_t i, len;
156
157 len = PySequence_Length(py_fds_to_keep);
158 for (i = 0; i < len; ++i) {
159 PyObject* fdobj = PySequence_Fast_GET_ITEM(py_fds_to_keep, i);
160 long fd = PyLong_AsLong(fdobj);
161 assert(!PyErr_Occurred());
162 assert(0 <= fd && fd <= INT_MAX);
163 if (fd == errpipe_write) {
164 /* errpipe_write is part of py_fds_to_keep. It must be closed at
165 exec(), but kept open in the child process until exec() is
166 called. */
167 continue;
168 }
169 if (_Py_set_inheritable((int)fd, 1, NULL) < 0)
170 return -1;
171 }
172 return 0;
173}
174
Gregory P. Smith8facece2012-01-21 14:01:08 -0800175
Gregory P. Smithd4dcb702014-06-01 13:18:28 -0700176/* Get the maximum file descriptor that could be opened by this process.
177 * This function is async signal safe for use between fork() and exec().
178 */
179static long
180safe_get_max_fd(void)
181{
182 long local_max_fd;
183#if defined(__NetBSD__)
184 local_max_fd = fcntl(0, F_MAXFD);
185 if (local_max_fd >= 0)
186 return local_max_fd;
187#endif
Gregory P. Smithf9681772015-04-25 23:43:34 -0700188#if defined(HAVE_SYS_RESOURCE_H) && defined(__OpenBSD__)
189 struct rlimit rl;
190 /* Not on the POSIX async signal safe functions list but likely
191 * safe. TODO - Someone should audit OpenBSD to make sure. */
192 if (getrlimit(RLIMIT_NOFILE, &rl) >= 0)
193 return (long) rl.rlim_max;
194#endif
Gregory P. Smithd4dcb702014-06-01 13:18:28 -0700195#ifdef _SC_OPEN_MAX
196 local_max_fd = sysconf(_SC_OPEN_MAX);
197 if (local_max_fd == -1)
198#endif
199 local_max_fd = 256; /* Matches legacy Lib/subprocess.py behavior. */
200 return local_max_fd;
201}
202
203
204/* Close all file descriptors in the range from start_fd and higher
205 * except for those in py_fds_to_keep. If the range defined by
206 * [start_fd, safe_get_max_fd()) is large this will take a long
207 * time as it calls close() on EVERY possible fd.
208 *
209 * It isn't possible to know for sure what the max fd to go up to
210 * is for processes with the capability of raising their maximum.
Gregory P. Smith8facece2012-01-21 14:01:08 -0800211 */
Benjamin Peterson91eef982012-01-22 20:04:46 -0500212static void
Gregory P. Smithd4dcb702014-06-01 13:18:28 -0700213_close_fds_by_brute_force(long start_fd, PyObject *py_fds_to_keep)
Gregory P. Smith8facece2012-01-21 14:01:08 -0800214{
Gregory P. Smithd4dcb702014-06-01 13:18:28 -0700215 long end_fd = safe_get_max_fd();
Gregory P. Smith8facece2012-01-21 14:01:08 -0800216 Py_ssize_t num_fds_to_keep = PySequence_Length(py_fds_to_keep);
217 Py_ssize_t keep_seq_idx;
218 int fd_num;
219 /* As py_fds_to_keep is sorted we can loop through the list closing
220 * fds inbetween any in the keep list falling within our range. */
221 for (keep_seq_idx = 0; keep_seq_idx < num_fds_to_keep; ++keep_seq_idx) {
222 PyObject* py_keep_fd = PySequence_Fast_GET_ITEM(py_fds_to_keep,
223 keep_seq_idx);
224 int keep_fd = PyLong_AsLong(py_keep_fd);
225 if (keep_fd < start_fd)
226 continue;
227 for (fd_num = start_fd; fd_num < keep_fd; ++fd_num) {
Victor Stinnere7c74922015-04-02 16:24:46 +0200228 close(fd_num);
Gregory P. Smith8facece2012-01-21 14:01:08 -0800229 }
230 start_fd = keep_fd + 1;
231 }
232 if (start_fd <= end_fd) {
233 for (fd_num = start_fd; fd_num < end_fd; ++fd_num) {
Victor Stinnere7c74922015-04-02 16:24:46 +0200234 close(fd_num);
Gregory P. Smith8facece2012-01-21 14:01:08 -0800235 }
236 }
237}
238
239
240#if defined(__linux__) && defined(HAVE_SYS_SYSCALL_H)
241/* It doesn't matter if d_name has room for NAME_MAX chars; we're using this
242 * only to read a directory of short file descriptor number names. The kernel
243 * will return an error if we didn't give it enough space. Highly Unlikely.
244 * This structure is very old and stable: It will not change unless the kernel
245 * chooses to break compatibility with all existing binaries. Highly Unlikely.
246 */
Gregory P. Smith255bf5b2013-03-03 10:45:05 -0800247struct linux_dirent64 {
Gregory P. Smith58f07a92012-06-05 13:26:39 -0700248 unsigned long long d_ino;
Gregory P. Smith255bf5b2013-03-03 10:45:05 -0800249 long long d_off;
Gregory P. Smith8facece2012-01-21 14:01:08 -0800250 unsigned short d_reclen; /* Length of this linux_dirent */
Gregory P. Smith255bf5b2013-03-03 10:45:05 -0800251 unsigned char d_type;
Gregory P. Smith8facece2012-01-21 14:01:08 -0800252 char d_name[256]; /* Filename (null-terminated) */
253};
254
Gregory P. Smitha26987a2014-06-01 13:46:36 -0700255/* Close all open file descriptors in the range from start_fd and higher
256 * Do not close any in the sorted py_fds_to_keep list.
Gregory P. Smith8facece2012-01-21 14:01:08 -0800257 *
258 * This version is async signal safe as it does not make any unsafe C library
259 * calls, malloc calls or handle any locks. It is _unfortunate_ to be forced
260 * to resort to making a kernel system call directly but this is the ONLY api
261 * available that does no harm. opendir/readdir/closedir perform memory
262 * allocation and locking so while they usually work they are not guaranteed
263 * to (especially if you have replaced your malloc implementation). A version
264 * of this function that uses those can be found in the _maybe_unsafe variant.
265 *
266 * This is Linux specific because that is all I am ready to test it on. It
267 * should be easy to add OS specific dirent or dirent64 structures and modify
268 * it with some cpp #define magic to work on other OSes as well if you want.
269 */
Benjamin Peterson91eef982012-01-22 20:04:46 -0500270static void
Gregory P. Smithd4dcb702014-06-01 13:18:28 -0700271_close_open_fds_safe(int start_fd, PyObject* py_fds_to_keep)
Gregory P. Smith8facece2012-01-21 14:01:08 -0800272{
273 int fd_dir_fd;
Victor Stinnerdaf45552013-08-28 00:53:59 +0200274
Victor Stinner160e8192015-03-30 02:18:31 +0200275 fd_dir_fd = _Py_open_noraise(FD_DIR, O_RDONLY);
Gregory P. Smith8facece2012-01-21 14:01:08 -0800276 if (fd_dir_fd == -1) {
277 /* No way to get a list of open fds. */
Gregory P. Smithd4dcb702014-06-01 13:18:28 -0700278 _close_fds_by_brute_force(start_fd, py_fds_to_keep);
Gregory P. Smith8facece2012-01-21 14:01:08 -0800279 return;
280 } else {
Gregory P. Smith255bf5b2013-03-03 10:45:05 -0800281 char buffer[sizeof(struct linux_dirent64)];
Gregory P. Smith8facece2012-01-21 14:01:08 -0800282 int bytes;
Gregory P. Smith255bf5b2013-03-03 10:45:05 -0800283 while ((bytes = syscall(SYS_getdents64, fd_dir_fd,
284 (struct linux_dirent64 *)buffer,
Gregory P. Smith8facece2012-01-21 14:01:08 -0800285 sizeof(buffer))) > 0) {
Gregory P. Smith255bf5b2013-03-03 10:45:05 -0800286 struct linux_dirent64 *entry;
Gregory P. Smith8facece2012-01-21 14:01:08 -0800287 int offset;
288 for (offset = 0; offset < bytes; offset += entry->d_reclen) {
289 int fd;
Gregory P. Smith255bf5b2013-03-03 10:45:05 -0800290 entry = (struct linux_dirent64 *)(buffer + offset);
Gregory P. Smith8facece2012-01-21 14:01:08 -0800291 if ((fd = _pos_int_from_ascii(entry->d_name)) < 0)
292 continue; /* Not a number. */
Gregory P. Smithd4dcb702014-06-01 13:18:28 -0700293 if (fd != fd_dir_fd && fd >= start_fd &&
Gregory P. Smith8facece2012-01-21 14:01:08 -0800294 !_is_fd_in_sorted_fd_sequence(fd, py_fds_to_keep)) {
Victor Stinnere7c74922015-04-02 16:24:46 +0200295 close(fd);
Gregory P. Smith8facece2012-01-21 14:01:08 -0800296 }
297 }
298 }
Victor Stinnere7c74922015-04-02 16:24:46 +0200299 close(fd_dir_fd);
Gregory P. Smith8facece2012-01-21 14:01:08 -0800300 }
301}
302
Gregory P. Smithd4dcb702014-06-01 13:18:28 -0700303#define _close_open_fds _close_open_fds_safe
Gregory P. Smith8facece2012-01-21 14:01:08 -0800304
305#else /* NOT (defined(__linux__) && defined(HAVE_SYS_SYSCALL_H)) */
306
307
Gregory P. Smithd4dcb702014-06-01 13:18:28 -0700308/* Close all open file descriptors from start_fd and higher.
309 * Do not close any in the sorted py_fds_to_keep list.
Gregory P. Smith8facece2012-01-21 14:01:08 -0800310 *
311 * This function violates the strict use of async signal safe functions. :(
Gregory P. Smithe3f78482012-01-21 15:16:17 -0800312 * It calls opendir(), readdir() and closedir(). Of these, the one most
Gregory P. Smith8facece2012-01-21 14:01:08 -0800313 * likely to ever cause a problem is opendir() as it performs an internal
314 * malloc(). Practically this should not be a problem. The Java VM makes the
315 * same calls between fork and exec in its own UNIXProcess_md.c implementation.
316 *
317 * readdir_r() is not used because it provides no benefit. It is typically
318 * implemented as readdir() followed by memcpy(). See also:
319 * http://womble.decadent.org.uk/readdir_r-advisory.html
320 */
Benjamin Peterson91eef982012-01-22 20:04:46 -0500321static void
Gregory P. Smithd4dcb702014-06-01 13:18:28 -0700322_close_open_fds_maybe_unsafe(long start_fd, PyObject* py_fds_to_keep)
Gregory P. Smith8facece2012-01-21 14:01:08 -0800323{
324 DIR *proc_fd_dir;
325#ifndef HAVE_DIRFD
Gregory P. Smithd4dcb702014-06-01 13:18:28 -0700326 while (_is_fd_in_sorted_fd_sequence(start_fd, py_fds_to_keep)) {
Gregory P. Smith8facece2012-01-21 14:01:08 -0800327 ++start_fd;
328 }
Gregory P. Smith8facece2012-01-21 14:01:08 -0800329 /* Close our lowest fd before we call opendir so that it is likely to
330 * reuse that fd otherwise we might close opendir's file descriptor in
331 * our loop. This trick assumes that fd's are allocated on a lowest
332 * available basis. */
Victor Stinnere7c74922015-04-02 16:24:46 +0200333 close(start_fd);
Gregory P. Smith8facece2012-01-21 14:01:08 -0800334 ++start_fd;
335#endif
Gregory P. Smith8facece2012-01-21 14:01:08 -0800336
Gregory P. Smith4842efc2012-01-21 21:01:24 -0800337#if defined(__FreeBSD__)
338 if (!_is_fdescfs_mounted_on_dev_fd())
339 proc_fd_dir = NULL;
340 else
341#endif
342 proc_fd_dir = opendir(FD_DIR);
Gregory P. Smith8facece2012-01-21 14:01:08 -0800343 if (!proc_fd_dir) {
344 /* No way to get a list of open fds. */
Gregory P. Smithd4dcb702014-06-01 13:18:28 -0700345 _close_fds_by_brute_force(start_fd, py_fds_to_keep);
Gregory P. Smith8facece2012-01-21 14:01:08 -0800346 } else {
Gregory P. Smithe3f78482012-01-21 15:16:17 -0800347 struct dirent *dir_entry;
Gregory P. Smith8facece2012-01-21 14:01:08 -0800348#ifdef HAVE_DIRFD
Gregory P. Smithe9b7cab2012-01-21 15:19:11 -0800349 int fd_used_by_opendir = dirfd(proc_fd_dir);
Gregory P. Smith8facece2012-01-21 14:01:08 -0800350#else
351 int fd_used_by_opendir = start_fd - 1;
352#endif
353 errno = 0;
Gregory P. Smithe3f78482012-01-21 15:16:17 -0800354 while ((dir_entry = readdir(proc_fd_dir))) {
Gregory P. Smith8facece2012-01-21 14:01:08 -0800355 int fd;
356 if ((fd = _pos_int_from_ascii(dir_entry->d_name)) < 0)
357 continue; /* Not a number. */
Gregory P. Smithd4dcb702014-06-01 13:18:28 -0700358 if (fd != fd_used_by_opendir && fd >= start_fd &&
Gregory P. Smith8facece2012-01-21 14:01:08 -0800359 !_is_fd_in_sorted_fd_sequence(fd, py_fds_to_keep)) {
Victor Stinnere7c74922015-04-02 16:24:46 +0200360 close(fd);
Gregory P. Smith8facece2012-01-21 14:01:08 -0800361 }
362 errno = 0;
363 }
364 if (errno) {
365 /* readdir error, revert behavior. Highly Unlikely. */
Gregory P. Smithd4dcb702014-06-01 13:18:28 -0700366 _close_fds_by_brute_force(start_fd, py_fds_to_keep);
Gregory P. Smith8facece2012-01-21 14:01:08 -0800367 }
368 closedir(proc_fd_dir);
369 }
370}
371
Gregory P. Smithd4dcb702014-06-01 13:18:28 -0700372#define _close_open_fds _close_open_fds_maybe_unsafe
Gregory P. Smith8facece2012-01-21 14:01:08 -0800373
374#endif /* else NOT (defined(__linux__) && defined(HAVE_SYS_SYSCALL_H)) */
375
376
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000377/*
378 * This function is code executed in the child process immediately after fork
379 * to set things up and call exec().
380 *
381 * All of the code in this function must only use async-signal-safe functions,
382 * listed at `man 7 signal` or
383 * http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_04.html.
384 *
385 * This restriction is documented at
386 * http://www.opengroup.org/onlinepubs/009695399/functions/fork.html.
387 */
Benjamin Peterson91eef982012-01-22 20:04:46 -0500388static void
389child_exec(char *const exec_array[],
390 char *const argv[],
391 char *const envp[],
392 const char *cwd,
393 int p2cread, int p2cwrite,
394 int c2pread, int c2pwrite,
395 int errread, int errwrite,
396 int errpipe_read, int errpipe_write,
397 int close_fds, int restore_signals,
398 int call_setsid,
399 PyObject *py_fds_to_keep,
400 PyObject *preexec_fn,
401 PyObject *preexec_fn_args_tuple)
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000402{
Victor Stinner185fd332015-04-01 18:35:53 +0200403 int i, saved_errno, reached_preexec = 0;
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000404 PyObject *result;
Gregory P. Smith14affb82010-12-22 05:22:17 +0000405 const char* err_msg = "";
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000406 /* Buffer large enough to hold a hex integer. We can't malloc. */
407 char hex_errno[sizeof(saved_errno)*2+1];
408
Victor Stinnerdaf45552013-08-28 00:53:59 +0200409 if (make_inheritable(py_fds_to_keep, errpipe_write) < 0)
410 goto error;
411
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000412 /* Close parent's pipe ends. */
Victor Stinnerdaf45552013-08-28 00:53:59 +0200413 if (p2cwrite != -1)
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000414 POSIX_CALL(close(p2cwrite));
Victor Stinnerdaf45552013-08-28 00:53:59 +0200415 if (c2pread != -1)
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000416 POSIX_CALL(close(c2pread));
Victor Stinnerdaf45552013-08-28 00:53:59 +0200417 if (errread != -1)
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000418 POSIX_CALL(close(errread));
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000419 POSIX_CALL(close(errpipe_read));
420
Ross Lagerwalld98646e2011-07-27 07:16:31 +0200421 /* When duping fds, if there arises a situation where one of the fds is
422 either 0, 1 or 2, it is possible that it is overwritten (#12607). */
423 if (c2pwrite == 0)
424 POSIX_CALL(c2pwrite = dup(c2pwrite));
425 if (errwrite == 0 || errwrite == 1)
426 POSIX_CALL(errwrite = dup(errwrite));
427
Antoine Pitrouc9c83ba2011-01-03 18:23:55 +0000428 /* Dup fds for child.
429 dup2() removes the CLOEXEC flag but we must do it ourselves if dup2()
430 would be a no-op (issue #10806). */
431 if (p2cread == 0) {
Victor Stinnerdaf45552013-08-28 00:53:59 +0200432 if (_Py_set_inheritable(p2cread, 1, NULL) < 0)
433 goto error;
434 }
435 else if (p2cread != -1)
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000436 POSIX_CALL(dup2(p2cread, 0)); /* stdin */
Victor Stinnerdaf45552013-08-28 00:53:59 +0200437
Antoine Pitrouc9c83ba2011-01-03 18:23:55 +0000438 if (c2pwrite == 1) {
Victor Stinnerdaf45552013-08-28 00:53:59 +0200439 if (_Py_set_inheritable(c2pwrite, 1, NULL) < 0)
440 goto error;
441 }
442 else if (c2pwrite != -1)
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000443 POSIX_CALL(dup2(c2pwrite, 1)); /* stdout */
Victor Stinnerdaf45552013-08-28 00:53:59 +0200444
Antoine Pitrouc9c83ba2011-01-03 18:23:55 +0000445 if (errwrite == 2) {
Victor Stinnerdaf45552013-08-28 00:53:59 +0200446 if (_Py_set_inheritable(errwrite, 1, NULL) < 0)
447 goto error;
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000448 }
Victor Stinnerdaf45552013-08-28 00:53:59 +0200449 else if (errwrite != -1)
450 POSIX_CALL(dup2(errwrite, 2)); /* stderr */
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000451
452 /* Close pipe fds. Make sure we don't close the same fd more than */
453 /* once, or standard fds. */
Victor Stinnerdaf45552013-08-28 00:53:59 +0200454 if (p2cread > 2)
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000455 POSIX_CALL(close(p2cread));
Victor Stinnerdaf45552013-08-28 00:53:59 +0200456 if (c2pwrite > 2 && c2pwrite != p2cread)
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000457 POSIX_CALL(close(c2pwrite));
Victor Stinnerdaf45552013-08-28 00:53:59 +0200458 if (errwrite != c2pwrite && errwrite != p2cread && errwrite > 2)
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000459 POSIX_CALL(close(errwrite));
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000460
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000461 if (cwd)
462 POSIX_CALL(chdir(cwd));
463
464 if (restore_signals)
465 _Py_RestoreSignals();
466
467#ifdef HAVE_SETSID
468 if (call_setsid)
469 POSIX_CALL(setsid());
470#endif
471
Gregory P. Smith5591b022012-10-10 03:34:47 -0700472 reached_preexec = 1;
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000473 if (preexec_fn != Py_None && preexec_fn_args_tuple) {
474 /* This is where the user has asked us to deadlock their program. */
475 result = PyObject_Call(preexec_fn, preexec_fn_args_tuple, NULL);
476 if (result == NULL) {
477 /* Stringifying the exception or traceback would involve
478 * memory allocation and thus potential for deadlock.
479 * We've already faced potential deadlock by calling back
480 * into Python in the first place, so it probably doesn't
481 * matter but we avoid it to minimize the possibility. */
482 err_msg = "Exception occurred in preexec_fn.";
483 errno = 0; /* We don't want to report an OSError. */
484 goto error;
485 }
486 /* Py_DECREF(result); - We're about to exec so why bother? */
487 }
488
Charles-François Natali249cdc32013-08-25 18:24:45 +0200489 /* close FDs after executing preexec_fn, which might open FDs */
490 if (close_fds) {
Charles-François Natali249cdc32013-08-25 18:24:45 +0200491 /* TODO HP-UX could use pstat_getproc() if anyone cares about it. */
Gregory P. Smithd4dcb702014-06-01 13:18:28 -0700492 _close_open_fds(3, py_fds_to_keep);
Charles-François Natali249cdc32013-08-25 18:24:45 +0200493 }
494
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000495 /* This loop matches the Lib/os.py _execvpe()'s PATH search when */
496 /* given the executable_list generated by Lib/subprocess.py. */
497 saved_errno = 0;
498 for (i = 0; exec_array[i] != NULL; ++i) {
499 const char *executable = exec_array[i];
500 if (envp) {
501 execve(executable, argv, envp);
502 } else {
503 execv(executable, argv);
504 }
505 if (errno != ENOENT && errno != ENOTDIR && saved_errno == 0) {
506 saved_errno = errno;
507 }
508 }
509 /* Report the first exec error, not the last. */
510 if (saved_errno)
511 errno = saved_errno;
512
513error:
514 saved_errno = errno;
515 /* Report the posix error to our parent process. */
Gregory P. Smith12fdca52012-01-21 12:31:25 -0800516 /* We ignore all write() return values as the total size of our writes is
Victor Stinner185fd332015-04-01 18:35:53 +0200517 less than PIPEBUF and we cannot do anything about an error anyways.
518 Use _Py_write_noraise() to retry write() if it is interrupted by a
519 signal (fails with EINTR). */
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000520 if (saved_errno) {
521 char *cur;
Victor Stinner185fd332015-04-01 18:35:53 +0200522 _Py_write_noraise(errpipe_write, "OSError:", 8);
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000523 cur = hex_errno + sizeof(hex_errno);
Serhiy Storchaka5ae4f492016-09-27 22:03:51 +0300524 while (saved_errno != 0 && cur != hex_errno) {
Gregory P. Smith4dff6f62015-04-25 23:42:38 +0000525 *--cur = Py_hexdigits[saved_errno % 16];
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000526 saved_errno /= 16;
527 }
Victor Stinner185fd332015-04-01 18:35:53 +0200528 _Py_write_noraise(errpipe_write, cur, hex_errno + sizeof(hex_errno) - cur);
529 _Py_write_noraise(errpipe_write, ":", 1);
Gregory P. Smith5591b022012-10-10 03:34:47 -0700530 if (!reached_preexec) {
531 /* Indicate to the parent that the error happened before exec(). */
Victor Stinner185fd332015-04-01 18:35:53 +0200532 _Py_write_noraise(errpipe_write, "noexec", 6);
Gregory P. Smith5591b022012-10-10 03:34:47 -0700533 }
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000534 /* We can't call strerror(saved_errno). It is not async signal safe.
535 * The parent process will look the error message up. */
536 } else {
Victor Stinner185fd332015-04-01 18:35:53 +0200537 _Py_write_noraise(errpipe_write, "SubprocessError:0:", 18);
538 _Py_write_noraise(errpipe_write, err_msg, strlen(err_msg));
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000539 }
540}
541
542
543static PyObject *
544subprocess_fork_exec(PyObject* self, PyObject *args)
545{
546 PyObject *gc_module = NULL;
Antoine Pitrou721738f2012-08-15 23:20:39 +0200547 PyObject *executable_list, *py_fds_to_keep;
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000548 PyObject *env_list, *preexec_fn;
Gregory P. Smith68f52172010-03-15 06:07:42 +0000549 PyObject *process_args, *converted_args = NULL, *fast_args = NULL;
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000550 PyObject *preexec_fn_args_tuple = NULL;
551 int p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite;
552 int errpipe_read, errpipe_write, close_fds, restore_signals;
553 int call_setsid;
Victor Stinner0e59cc32010-04-16 23:49:32 +0000554 PyObject *cwd_obj, *cwd_obj2;
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000555 const char *cwd;
556 pid_t pid;
557 int need_to_reenable_gc = 0;
558 char *const *exec_array, *const *argv = NULL, *const *envp = NULL;
Gregory P. Smith8facece2012-01-21 14:01:08 -0800559 Py_ssize_t arg_num;
Victor Stinnerbc5b80b2015-10-11 09:54:42 +0200560#ifdef WITH_THREAD
Victor Stinner8f437aa2014-10-05 17:25:19 +0200561 int import_lock_held = 0;
Victor Stinnerbc5b80b2015-10-11 09:54:42 +0200562#endif
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000563
564 if (!PyArg_ParseTuple(
Antoine Pitrou721738f2012-08-15 23:20:39 +0200565 args, "OOpOOOiiiiiiiiiiO:fork_exec",
566 &process_args, &executable_list, &close_fds, &py_fds_to_keep,
Victor Stinner0e59cc32010-04-16 23:49:32 +0000567 &cwd_obj, &env_list,
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000568 &p2cread, &p2cwrite, &c2pread, &c2pwrite,
569 &errread, &errwrite, &errpipe_read, &errpipe_write,
570 &restore_signals, &call_setsid, &preexec_fn))
571 return NULL;
572
Gregory P. Smith361e30c2013-12-01 00:12:24 -0800573 if (close_fds && errpipe_write < 3) { /* precondition */
574 PyErr_SetString(PyExc_ValueError, "errpipe_write must be >= 3");
575 return NULL;
576 }
Gregory P. Smith8facece2012-01-21 14:01:08 -0800577 if (PySequence_Length(py_fds_to_keep) < 0) {
578 PyErr_SetString(PyExc_ValueError, "cannot get length of fds_to_keep");
579 return NULL;
580 }
581 if (_sanity_check_python_fd_sequence(py_fds_to_keep)) {
582 PyErr_SetString(PyExc_ValueError, "bad value(s) in fds_to_keep");
Gregory P. Smithd4cc7bf2010-12-04 11:22:11 +0000583 return NULL;
584 }
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000585
586 /* We need to call gc.disable() when we'll be calling preexec_fn */
587 if (preexec_fn != Py_None) {
588 PyObject *result;
Martin v. Löwisbd928fe2011-10-14 10:20:37 +0200589 _Py_IDENTIFIER(isenabled);
590 _Py_IDENTIFIER(disable);
Victor Stinnerdaf45552013-08-28 00:53:59 +0200591
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000592 gc_module = PyImport_ImportModule("gc");
593 if (gc_module == NULL)
594 return NULL;
Martin v. Löwisafe55bb2011-10-09 10:38:36 +0200595 result = _PyObject_CallMethodId(gc_module, &PyId_isenabled, NULL);
Gregory P. Smith32ec9da2010-03-19 16:53:08 +0000596 if (result == NULL) {
597 Py_DECREF(gc_module);
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000598 return NULL;
Gregory P. Smith32ec9da2010-03-19 16:53:08 +0000599 }
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000600 need_to_reenable_gc = PyObject_IsTrue(result);
601 Py_DECREF(result);
Gregory P. Smith32ec9da2010-03-19 16:53:08 +0000602 if (need_to_reenable_gc == -1) {
603 Py_DECREF(gc_module);
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000604 return NULL;
Gregory P. Smith32ec9da2010-03-19 16:53:08 +0000605 }
Martin v. Löwisafe55bb2011-10-09 10:38:36 +0200606 result = _PyObject_CallMethodId(gc_module, &PyId_disable, NULL);
Gregory P. Smith32ec9da2010-03-19 16:53:08 +0000607 if (result == NULL) {
608 Py_DECREF(gc_module);
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000609 return NULL;
Gregory P. Smith32ec9da2010-03-19 16:53:08 +0000610 }
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000611 Py_DECREF(result);
612 }
613
614 exec_array = _PySequence_BytesToCharpArray(executable_list);
Victor Stinner8f437aa2014-10-05 17:25:19 +0200615 if (!exec_array)
616 goto cleanup;
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000617
618 /* Convert args and env into appropriate arguments for exec() */
619 /* These conversions are done in the parent process to avoid allocating
620 or freeing memory in the child process. */
621 if (process_args != Py_None) {
Gregory P. Smith68f52172010-03-15 06:07:42 +0000622 Py_ssize_t num_args;
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000623 /* Equivalent to: */
624 /* tuple(PyUnicode_FSConverter(arg) for arg in process_args) */
Gregory P. Smith68f52172010-03-15 06:07:42 +0000625 fast_args = PySequence_Fast(process_args, "argv must be a tuple");
Stefan Krahdb579d72012-08-20 14:36:47 +0200626 if (fast_args == NULL)
627 goto cleanup;
Gregory P. Smith68f52172010-03-15 06:07:42 +0000628 num_args = PySequence_Fast_GET_SIZE(fast_args);
629 converted_args = PyTuple_New(num_args);
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000630 if (converted_args == NULL)
631 goto cleanup;
Gregory P. Smith68f52172010-03-15 06:07:42 +0000632 for (arg_num = 0; arg_num < num_args; ++arg_num) {
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000633 PyObject *borrowed_arg, *converted_arg;
Gregory P. Smith68f52172010-03-15 06:07:42 +0000634 borrowed_arg = PySequence_Fast_GET_ITEM(fast_args, arg_num);
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000635 if (PyUnicode_FSConverter(borrowed_arg, &converted_arg) == 0)
636 goto cleanup;
637 PyTuple_SET_ITEM(converted_args, arg_num, converted_arg);
638 }
639
640 argv = _PySequence_BytesToCharpArray(converted_args);
641 Py_CLEAR(converted_args);
Gregory P. Smith68f52172010-03-15 06:07:42 +0000642 Py_CLEAR(fast_args);
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000643 if (!argv)
644 goto cleanup;
645 }
646
647 if (env_list != Py_None) {
648 envp = _PySequence_BytesToCharpArray(env_list);
649 if (!envp)
650 goto cleanup;
651 }
652
653 if (preexec_fn != Py_None) {
654 preexec_fn_args_tuple = PyTuple_New(0);
655 if (!preexec_fn_args_tuple)
656 goto cleanup;
Victor Stinnerbc5b80b2015-10-11 09:54:42 +0200657#ifdef WITH_THREAD
Victor Stinner0e59cc32010-04-16 23:49:32 +0000658 _PyImport_AcquireLock();
Victor Stinner8f437aa2014-10-05 17:25:19 +0200659 import_lock_held = 1;
Victor Stinnerbc5b80b2015-10-11 09:54:42 +0200660#endif
Victor Stinner0e59cc32010-04-16 23:49:32 +0000661 }
662
663 if (cwd_obj != Py_None) {
664 if (PyUnicode_FSConverter(cwd_obj, &cwd_obj2) == 0)
665 goto cleanup;
Victor Stinnerdcb24032010-04-22 12:08:36 +0000666 cwd = PyBytes_AsString(cwd_obj2);
Victor Stinner0e59cc32010-04-16 23:49:32 +0000667 } else {
668 cwd = NULL;
669 cwd_obj2 = NULL;
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000670 }
671
672 pid = fork();
673 if (pid == 0) {
674 /* Child process */
Victor Stinner0e59cc32010-04-16 23:49:32 +0000675 /*
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000676 * Code from here to _exit() must only use async-signal-safe functions,
677 * listed at `man 7 signal` or
678 * http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_04.html.
679 */
680
681 if (preexec_fn != Py_None) {
682 /* We'll be calling back into Python later so we need to do this.
683 * This call may not be async-signal-safe but neither is calling
684 * back into Python. The user asked us to use hope as a strategy
685 * to avoid deadlock... */
686 PyOS_AfterFork();
687 }
688
689 child_exec(exec_array, argv, envp, cwd,
690 p2cread, p2cwrite, c2pread, c2pwrite,
691 errread, errwrite, errpipe_read, errpipe_write,
692 close_fds, restore_signals, call_setsid,
Gregory P. Smith8facece2012-01-21 14:01:08 -0800693 py_fds_to_keep, preexec_fn, preexec_fn_args_tuple);
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000694 _exit(255);
695 return NULL; /* Dead code to avoid a potential compiler warning. */
696 }
Victor Stinner0e59cc32010-04-16 23:49:32 +0000697 Py_XDECREF(cwd_obj2);
698
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000699 if (pid == -1) {
700 /* Capture the errno exception before errno can be clobbered. */
701 PyErr_SetFromErrno(PyExc_OSError);
702 }
Victor Stinnerbc5b80b2015-10-11 09:54:42 +0200703#ifdef WITH_THREAD
704 if (preexec_fn != Py_None
705 && _PyImport_ReleaseLock() < 0 && !PyErr_Occurred()) {
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000706 PyErr_SetString(PyExc_RuntimeError,
707 "not holding the import lock");
Martin Panterafdd5132015-11-30 02:21:41 +0000708 pid = -1;
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000709 }
Victor Stinner8f437aa2014-10-05 17:25:19 +0200710 import_lock_held = 0;
Victor Stinnerbc5b80b2015-10-11 09:54:42 +0200711#endif
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000712
713 /* Parent process */
714 if (envp)
715 _Py_FreeCharPArray(envp);
716 if (argv)
717 _Py_FreeCharPArray(argv);
718 _Py_FreeCharPArray(exec_array);
719
720 /* Reenable gc in the parent process (or if fork failed). */
Martin Panterafdd5132015-11-30 02:21:41 +0000721 if (_enable_gc(need_to_reenable_gc, gc_module)) {
722 pid = -1;
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000723 }
Gregory P. Smith32ec9da2010-03-19 16:53:08 +0000724 Py_XDECREF(preexec_fn_args_tuple);
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000725 Py_XDECREF(gc_module);
726
727 if (pid == -1)
728 return NULL; /* fork() failed. Exception set earlier. */
729
730 return PyLong_FromPid(pid);
731
732cleanup:
Victor Stinnerbc5b80b2015-10-11 09:54:42 +0200733#ifdef WITH_THREAD
Victor Stinner8f437aa2014-10-05 17:25:19 +0200734 if (import_lock_held)
735 _PyImport_ReleaseLock();
Victor Stinnerbc5b80b2015-10-11 09:54:42 +0200736#endif
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000737 if (envp)
738 _Py_FreeCharPArray(envp);
739 if (argv)
740 _Py_FreeCharPArray(argv);
Victor Stinner8f437aa2014-10-05 17:25:19 +0200741 if (exec_array)
742 _Py_FreeCharPArray(exec_array);
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000743 Py_XDECREF(converted_args);
Gregory P. Smith68f52172010-03-15 06:07:42 +0000744 Py_XDECREF(fast_args);
Gregory P. Smith32ec9da2010-03-19 16:53:08 +0000745 Py_XDECREF(preexec_fn_args_tuple);
Martin Panterafdd5132015-11-30 02:21:41 +0000746 _enable_gc(need_to_reenable_gc, gc_module);
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000747 Py_XDECREF(gc_module);
748 return NULL;
749}
750
751
752PyDoc_STRVAR(subprocess_fork_exec_doc,
753"fork_exec(args, executable_list, close_fds, cwd, env,\n\
754 p2cread, p2cwrite, c2pread, c2pwrite,\n\
755 errread, errwrite, errpipe_read, errpipe_write,\n\
756 restore_signals, call_setsid, preexec_fn)\n\
757\n\
758Forks a child process, closes parent file descriptors as appropriate in the\n\
759child and dups the few that are needed before calling exec() in the child\n\
760process.\n\
761\n\
762The preexec_fn, if supplied, will be called immediately before exec.\n\
763WARNING: preexec_fn is NOT SAFE if your application uses threads.\n\
764 It may trigger infrequent, difficult to debug deadlocks.\n\
765\n\
766If an error occurs in the child process before the exec, it is\n\
767serialized and written to the errpipe_write fd per subprocess.py.\n\
768\n\
769Returns: the child process's PID.\n\
770\n\
771Raises: Only on an error in the parent process.\n\
772");
773
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000774/* module level code ********************************************************/
775
776PyDoc_STRVAR(module_doc,
777"A POSIX helper for the subprocess module.");
778
779
780static PyMethodDef module_methods[] = {
781 {"fork_exec", subprocess_fork_exec, METH_VARARGS, subprocess_fork_exec_doc},
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000782 {NULL, NULL} /* sentinel */
783};
784
785
786static struct PyModuleDef _posixsubprocessmodule = {
787 PyModuleDef_HEAD_INIT,
788 "_posixsubprocess",
789 module_doc,
790 -1, /* No memory is needed. */
791 module_methods,
792};
793
794PyMODINIT_FUNC
795PyInit__posixsubprocess(void)
796{
Gregory P. Smithfb94c5f2010-03-14 06:49:55 +0000797 return PyModule_Create(&_posixsubprocessmodule);
798}