joyent/libuv — pull request #1162 by maxtaco (2014-02-27 16:32:25+00:00)
Title: process: fix bug that mistakenly closes child stdin in some cases

If a parent process closes 0, and then calls spawn, the following will
happen:

- the first call to socketpair() will return a pair like [0,14]
in the parent. The kernel allocates fd=0 since it's the lowest
free file descriptor.
- the child, after fork, in uv__process_child_init,
calls dup2(use_fd=14,fd=0), which is fine.
- the child then calls close(close_fd=0), which is wrong.

This problem is easily solved by closing the close_fd first, and then
calling dup2 as before.