diff --git a/src/node_child_process.cc b/src/node_child_process.cc index e034a23114b..c971ad79fdf 100644 --- a/src/node_child_process.cc +++ b/src/node_child_process.cc @@ -34,6 +34,14 @@ static inline int SetNonBlocking(int fd) { } +static inline int SetBlocking(int fd) { + int flags = fcntl(fd, F_GETFL, 0); + int r = fcntl(fd, F_SETFL, flags ^ O_NONBLOCK); + if (r != 0) perror("SetBlocking()"); + return r; +} + + void ChildProcess::Initialize(Handle target) { HandleScope scope; @@ -222,24 +230,24 @@ int ChildProcess::Spawn(const char *file, if (custom_fds[0] == -1) { close(stdin_pipe[1]); // close write end dup2(stdin_pipe[0], STDIN_FILENO); - } - else { + } else { + SetBlocking(custom_fds[0]); dup2(custom_fds[0], STDIN_FILENO); } if (custom_fds[1] == -1) { close(stdout_pipe[0]); // close read end dup2(stdout_pipe[1], STDOUT_FILENO); - } - else { + } else { + SetBlocking(custom_fds[1]); dup2(custom_fds[1], STDOUT_FILENO); } if (custom_fds[2] == -1) { close(stderr_pipe[0]); // close read end dup2(stderr_pipe[1], STDERR_FILENO); - } - else { + } else { + SetBlocking(custom_fds[2]); dup2(custom_fds[2], STDERR_FILENO); }