Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unix: don't close the fds we just setup
If a descriptor was being copied to an fd that *was not its current value*, it should get closed after being copied. But the existing code would close the fd, even when it no longer referred to the original descriptor. Don't do this, only close fds that are not in the desired range for the child process. See nodejs/node#862
- Loading branch information
2d4939c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks correct to me but process.c is such a twisty maze of little if statements all alike that it took me 15 minutes of staring at the code and I'm still not 100% sure.
However, it does look like the close can be done right after the dup2 call a few lines up, allowing this loop to be removed. (Also,
close
should really beuv__close
.)Apropos that dup2 call, there is a potential for bugs there because it doesn't check the return code.
2d4939c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed :-S
Hum, But that would break if you want the child's fd 4 and 5 to be the partent's fd 42, right? because after you dup 42 into 4 you'd close it and on the next iteration you'd fail.
Indeed. AFAIS there is not much we can do other than ignoring it though...
2d4939c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, good point. Does the same logic apply to the
uv__close(close_fd)
call?2d4939c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, because close_fd will point to a fd we just opened to /dev/null, in order to redirect stdin, stdout and stderr to it, so in that case use_fd was -1.