Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
unix: code cleanup, rename variable
  • Loading branch information
bnoordhuis committed Sep 11, 2012
1 parent 12c25e1 commit b5028c5
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/unix/process.c
Expand Up @@ -205,26 +205,26 @@ static void uv__process_close_stream(uv_stdio_container_t* container) {
static void uv__process_child_init(uv_process_options_t options,
int stdio_count,
int* pipes) {
int i;
int fd;

if (options.flags & UV_PROCESS_DETACHED) {
setsid();
}

/* Dup fds */
for (i = 0; i < stdio_count; i++) {
for (fd = 0; fd < stdio_count; fd++) {
/*
* stdin has swapped ends of pipe
* (it's the only one readable stream)
*/
int close_fd = i == 0 ? pipes[i * 2 + 1] : pipes[i * 2];
int use_fd = i == 0 ? pipes[i * 2] : pipes[i * 2 + 1];
int close_fd = fd == 0 ? pipes[fd * 2 + 1] : pipes[fd * 2];
int use_fd = fd == 0 ? pipes[fd * 2] : pipes[fd * 2 + 1];

if (use_fd >= 0) {
close(close_fd);
} else if (i < 3) {
} else if (fd < 3) {
/* `/dev/null` stdin, stdout, stderr even if they've flag UV_IGNORE */
use_fd = open("/dev/null", i == 0 ? O_RDONLY : O_RDWR);
use_fd = open("/dev/null", fd == 0 ? O_RDONLY : O_RDWR);

if (use_fd < 0) {
perror("failed to open stdio");
Expand All @@ -234,8 +234,8 @@ static void uv__process_child_init(uv_process_options_t options,
continue;
}

if (i != use_fd) {
dup2(use_fd, i);
if (fd != use_fd) {
dup2(use_fd, fd);
close(use_fd);
} else {
uv__cloexec(use_fd, 0);
Expand Down

0 comments on commit b5028c5

Please sign in to comment.