ext/libuv/src/unix/process.c in libuv-4.0.1 vs ext/libuv/src/unix/process.c in libuv-4.0.2

- old
+ new

@@ -124,19 +124,19 @@ /* Retry on EINVAL, it means SOCK_CLOEXEC is not supported. * Anything else is a genuine error. */ if (errno != EINVAL) - return UV__ERR(errno); + return -errno; no_cloexec = 1; skip: #endif if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds)) - return UV__ERR(errno); + return -errno; uv__cloexec(fds[0], 1); uv__cloexec(fds[1], 1); if (flags & UV__F_NONBLOCK) { @@ -157,19 +157,19 @@ if (uv__pipe2(fds, flags | UV__O_CLOEXEC) == 0) return 0; if (errno != ENOSYS) - return UV__ERR(errno); + return -errno; no_pipe2 = 1; skip: #endif if (pipe(fds)) - return UV__ERR(errno); + return -errno; uv__cloexec(fds[0], 1); uv__cloexec(fds[1], 1); if (flags & UV__F_NONBLOCK) { @@ -196,11 +196,11 @@ return 0; case UV_CREATE_PIPE: assert(container->data.stream != NULL); if (container->data.stream->type != UV_NAMED_PIPE) - return UV_EINVAL; + return -EINVAL; else return uv__make_socketpair(fds, 0); case UV_INHERIT_FD: case UV_INHERIT_STREAM: @@ -208,24 +208,25 @@ fd = container->data.fd; else fd = uv__stream_fd(container->data.stream); if (fd == -1) - return UV_EINVAL; + return -EINVAL; fds[1] = fd; return 0; default: assert(0 && "Unexpected flags"); - return UV_EINVAL; + return -EINVAL; } } static int uv__process_open_stream(uv_stdio_container_t* container, - int pipefds[2]) { + int pipefds[2], + int writable) { int flags; int err; if (!(container->flags & UV_CREATE_PIPE) || pipefds[0] < 0) return 0; @@ -235,15 +236,17 @@ abort(); pipefds[1] = -1; uv__nonblock(pipefds[0], 1); - flags = 0; - if (container->flags & UV_WRITABLE_PIPE) - flags |= UV_STREAM_READABLE; - if (container->flags & UV_READABLE_PIPE) - flags |= UV_STREAM_WRITABLE; + 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); } @@ -294,11 +297,11 @@ use_fd = pipes[fd][1]; if (use_fd < 0 || use_fd >= fd) continue; pipes[fd][1] = fcntl(use_fd, F_DUPFD, stdio_count); if (pipes[fd][1] == -1) { - uv__write_int(error_fd, UV__ERR(errno)); + uv__write_int(error_fd, -errno); _exit(127); } } for (fd = 0; fd < stdio_count; fd++) { @@ -314,11 +317,11 @@ */ use_fd = open("/dev/null", fd == 0 ? O_RDONLY : O_RDWR); close_fd = use_fd; if (use_fd == -1) { - uv__write_int(error_fd, UV__ERR(errno)); + uv__write_int(error_fd, -errno); _exit(127); } } } @@ -326,11 +329,11 @@ uv__cloexec_fcntl(use_fd, 0); else fd = dup2(use_fd, fd); if (fd == -1) { - uv__write_int(error_fd, UV__ERR(errno)); + uv__write_int(error_fd, -errno); _exit(127); } if (fd <= 2) uv__nonblock_fcntl(fd, 0); @@ -345,11 +348,11 @@ if (use_fd >= stdio_count) uv__close(use_fd); } if (options->cwd != NULL && chdir(options->cwd)) { - uv__write_int(error_fd, UV__ERR(errno)); + uv__write_int(error_fd, -errno); _exit(127); } if (options->flags & (UV_PROCESS_SETUID | UV_PROCESS_SETGID)) { /* When dropping privileges from root, the `setgroups` call will @@ -361,16 +364,16 @@ */ SAVE_ERRNO(setgroups(0, NULL)); } if ((options->flags & UV_PROCESS_SETGID) && setgid(options->gid)) { - uv__write_int(error_fd, UV__ERR(errno)); + uv__write_int(error_fd, -errno); _exit(127); } if ((options->flags & UV_PROCESS_SETUID) && setuid(options->uid)) { - uv__write_int(error_fd, UV__ERR(errno)); + uv__write_int(error_fd, -errno); _exit(127); } if (options->env != NULL) { environ = options->env; @@ -386,36 +389,36 @@ continue; /* Can't be changed. */ if (SIG_ERR != signal(n, SIG_DFL)) continue; - uv__write_int(error_fd, UV__ERR(errno)); + uv__write_int(error_fd, -errno); _exit(127); } /* Reset signal mask. */ sigemptyset(&set); err = pthread_sigmask(SIG_SETMASK, &set, NULL); if (err != 0) { - uv__write_int(error_fd, UV__ERR(err)); + uv__write_int(error_fd, -err); _exit(127); } execvp(options->file, options->args); - uv__write_int(error_fd, UV__ERR(errno)); + uv__write_int(error_fd, -errno); _exit(127); } #endif int uv_spawn(uv_loop_t* loop, uv_process_t* process, const uv_process_options_t* options) { #if defined(__APPLE__) && (TARGET_OS_TV || TARGET_OS_WATCH) /* fork is marked __WATCHOS_PROHIBITED __TVOS_PROHIBITED. */ - return UV_ENOSYS; + return -ENOSYS; #else int signal_pipe[2] = { -1, -1 }; int pipes_storage[8][2]; int (*pipes)[2]; int stdio_count; @@ -438,11 +441,11 @@ stdio_count = options->stdio_count; if (stdio_count < 3) stdio_count = 3; - err = UV_ENOMEM; + err = -ENOMEM; pipes = pipes_storage; if (stdio_count > (int) ARRAY_SIZE(pipes_storage)) pipes = uv__malloc(stdio_count * sizeof(*pipes)); if (pipes == NULL) @@ -488,11 +491,11 @@ /* Acquire write lock to prevent opening new fds in worker threads */ uv_rwlock_wrlock(&loop->cloexec_lock); pid = fork(); if (pid == -1) { - err = UV__ERR(errno); + err = -errno; uv_rwlock_wrunlock(&loop->cloexec_lock); uv__close(signal_pipe[0]); uv__close(signal_pipe[1]); goto error; } @@ -528,11 +531,11 @@ abort(); uv__close_nocheckstdio(signal_pipe[0]); for (i = 0; i < options->stdio_count; i++) { - err = uv__process_open_stream(options->stdio + i, pipes[i]); + err = uv__process_open_stream(options->stdio + i, pipes[i], i == 0); if (err == 0) continue; while (i--) uv__process_close_stream(options->stdio + i); @@ -580,10 +583,10 @@ } int uv_kill(int pid, int signum) { if (kill(pid, signum)) - return UV__ERR(errno); + return -errno; else return 0; }