This repository has been archived by the owner on May 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 653
unix: don't close fd immediately after dup2() in uv_spawn() #923
Labels
Comments
Mind if I'll take a look at it? |
ghost
assigned indutny
Sep 7, 2013
Sure, go ahead. |
I'm reasonably sure the patch below fixes it but I'm unsure as to how correct it is. It passes all node and libuv tests but that doesn't mean it doesn't have bugs, of course. diff --git a/src/unix/process.c b/src/unix/process.c
index 990ea15..4d86089 100644
--- a/src/unix/process.c
+++ b/src/unix/process.c
@@ -285,8 +285,10 @@ static void uv__process_child_init(const uv_process_options_t* options,
close_fd = pipes[fd][0];
use_fd = pipes[fd][1];
- if (use_fd >= 0)
- close(close_fd);
+ if (use_fd >= 0) {
+ if (close_fd != -1)
+ close(close_fd);
+ }
else if (fd >= 3)
continue;
else {
@@ -304,15 +306,22 @@ static void uv__process_child_init(const uv_process_options_t* options,
if (fd == use_fd)
uv__cloexec(use_fd, 0);
- else {
+ else
dup2(use_fd, fd);
- close(use_fd);
- }
if (fd <= 2)
uv__nonblock(fd, 0);
}
+ for (fd = 0; fd < stdio_count; fd++) {
+ if (fd >= 3)
+ break;
+
+ use_fd = pipes[fd][1];
+ if (fd != use_fd)
+ close(use_fd);
+ }
+
if (options->cwd != NULL && chdir(options->cwd)) {
uv__write_int(error_fd, -errno);
perror("chdir()"); |
@bnoordhuis LGTM |
I found another bug in uv__process_child_init(), let me follow up with a more thorough patch. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Test case:
The text was updated successfully, but these errors were encountered: