From fb6b159d9ec7cf1e037daa974eeeacf3c8b3b3f1 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 3 Feb 2013 16:42:40 -0500 Subject: overhaul posix_spawn to use CLONE_VM instead of vfork the proposed change was described in detail in detail previously on the mailing list. in short, vfork is unsafe because: 1. the compiler could make optimizations that cause the child to clobber the parent's local vars. 2. strace is buggy and allows the vforking parent to run before the child execs when run under strace. the new design uses a close-on-exec pipe instead of vfork semantics to synchronize the parent and child so that the parent does not return before the child has finished using its arguments (and now, also its stack). this also allows reporting exec failures to the caller instead of giving the caller a child that mysteriously exits with status 127 on exec error. basic testing has been performed on both the success and failure code paths. further testing should be done. --- src/process/posix_spawn_file_actions_adddup2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/process/posix_spawn_file_actions_adddup2.c') diff --git a/src/process/posix_spawn_file_actions_adddup2.c b/src/process/posix_spawn_file_actions_adddup2.c index 26f2c5cc..0367498f 100644 --- a/src/process/posix_spawn_file_actions_adddup2.c +++ b/src/process/posix_spawn_file_actions_adddup2.c @@ -3,13 +3,13 @@ #include #include "fdop.h" -int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *fa, int fd, int newfd) +int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *fa, int srcfd, int fd) { struct fdop *op = malloc(sizeof *op); if (!op) return ENOMEM; op->cmd = FDOP_DUP2; + op->srcfd = srcfd; op->fd = fd; - op->newfd = newfd; if ((op->next = fa->__actions)) op->next->prev = op; op->prev = 0; fa->__actions = op; -- cgit v1.2.1