diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2013-01-11 13:49:45 +0100 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2013-01-11 14:00:19 +0100 |
commit | 31fc52ab53b5dde882ebadbbc912c2848c7b6a83 (patch) | |
tree | 11aa3925416fc156a9ccee5f37415a31d9104c52 /deps/uv/src/unix/process.c | |
parent | dc0c524ce681f53e2bd8f0974ed6aa3fd910054d (diff) | |
download | android-node-v8-31fc52ab53b5dde882ebadbbc912c2848c7b6a83.tar.gz android-node-v8-31fc52ab53b5dde882ebadbbc912c2848c7b6a83.tar.bz2 android-node-v8-31fc52ab53b5dde882ebadbbc912c2848c7b6a83.zip |
deps: upgrade libuv to 9aab5d4
Diffstat (limited to 'deps/uv/src/unix/process.c')
-rw-r--r-- | deps/uv/src/unix/process.c | 108 |
1 files changed, 46 insertions, 62 deletions
diff --git a/deps/uv/src/unix/process.c b/deps/uv/src/unix/process.c index c4df81a974..4c5714fa04 100644 --- a/deps/uv/src/unix/process.c +++ b/deps/uv/src/unix/process.c @@ -112,7 +112,7 @@ static void uv__chld(uv_signal_t* handle, int signum) { int uv__make_socketpair(int fds[2], int flags) { -#if __linux__ +#if defined(__linux__) static int no_cloexec; if (no_cloexec) @@ -148,7 +148,7 @@ skip: int uv__make_pipe(int fds[2], int flags) { -#if __linux__ +#if defined(__linux__) static int no_pipe2; if (no_pipe2) @@ -185,77 +185,69 @@ skip: * zero on success. */ static int uv__process_init_stdio(uv_stdio_container_t* container, int fds[2]) { - int fd = -1; - switch (container->flags & (UV_IGNORE | UV_CREATE_PIPE | UV_INHERIT_FD | - UV_INHERIT_STREAM)) { - case UV_IGNORE: - return 0; - case UV_CREATE_PIPE: - assert(container->data.stream != NULL); - - if (container->data.stream->type != UV_NAMED_PIPE) { - errno = EINVAL; - return -1; - } + int mask; + int fd; - return uv__make_socketpair(fds, 0); - case UV_INHERIT_FD: - case UV_INHERIT_STREAM: - if (container->flags & UV_INHERIT_FD) { - fd = container->data.fd; - } else { - fd = uv__stream_fd(container->data.stream); - } + mask = UV_IGNORE | UV_CREATE_PIPE | UV_INHERIT_FD | UV_INHERIT_STREAM; - if (fd == -1) { - errno = EINVAL; - return -1; - } + switch (container->flags & mask) { + case UV_IGNORE: + return 0; + + case UV_CREATE_PIPE: + assert(container->data.stream != NULL); + if (container->data.stream->type != UV_NAMED_PIPE) { + errno = EINVAL; + return -1; + } + return uv__make_socketpair(fds, 0); - fds[1] = fd; + case UV_INHERIT_FD: + case UV_INHERIT_STREAM: + if (container->flags & UV_INHERIT_FD) + fd = container->data.fd; + else + fd = uv__stream_fd(container->data.stream); - return 0; - default: - assert(0 && "Unexpected flags"); + if (fd == -1) { + errno = EINVAL; return -1; - } -} + } + fds[1] = fd; + return 0; -static int uv__process_stdio_flags(uv_stdio_container_t* container, - int writable) { - if (container->data.stream->type == UV_NAMED_PIPE && - ((uv_pipe_t*)container->data.stream)->ipc) { - return UV_STREAM_READABLE | UV_STREAM_WRITABLE; - } else if (writable) { - return UV_STREAM_WRITABLE; - } else { - return UV_STREAM_READABLE; + default: + assert(0 && "Unexpected flags"); + return -1; } } static int uv__process_open_stream(uv_stdio_container_t* container, - int fds[2], + int pipefds[2], int writable) { - int child_fd; int flags; - int fd; - - fd = fds[0]; - child_fd = fds[1]; - /* No need to create stream */ - if (!(container->flags & UV_CREATE_PIPE) || fd < 0) + if (!(container->flags & UV_CREATE_PIPE) || pipefds[0] < 0) return 0; - assert(child_fd >= 0); - close(child_fd); + if (close(pipefds[1])) + if (errno != EINTR && errno != EINPROGRESS) + abort(); - uv__nonblock(fd, 1); - flags = uv__process_stdio_flags(container, writable); + pipefds[1] = -1; + uv__nonblock(pipefds[0], 1); - return uv__stream_open((uv_stream_t*)container->data.stream, fd, flags); + if (container->data.stream->type == UV_NAMED_PIPE && + ((uv_pipe_t*)container->data.stream)->ipc) + flags = UV_STREAM_READABLE | UV_STREAM_WRITABLE; + else if (writable) + flags = UV_STREAM_WRITABLE; + else + flags = UV_STREAM_READABLE; + + return uv__stream_open(container->data.stream, pipefds[0], flags); } @@ -391,14 +383,6 @@ int uv_spawn(uv_loop_t* loop, if (uv__process_init_stdio(options.stdio + i, pipes[i])) goto error; - /* swap stdin file descriptors, it's the only writable stream */ - { - int* p = pipes[0]; - int t = p[0]; - p[0] = p[1]; - p[1] = t; - } - /* This pipe is used by the parent to wait until * the child has called `execve()`. We need this * to avoid the following race condition: |