Basically, in Node 0.6, if you start a child_process with
child_process.spawn, the pipe2 system call was used to create the
pipes between parent and child.
Now the socketpair call is used to create those fds.
I'm not sure why that choice was made, but it has at least one bad
effect: it breaks the ability to use "/dev/stdin" or "/proc/self/fd/0"
on the child, at least on Linux.
The gist shows a Node program that basically just spawns "cat
/proc/self/fd/0", closes the pipe to the cat, and shows what the cat
outputs. In 0.6.17 cat happily cats the empty stdin and exits 1. In
0.8.8 cat fails to open the /proc/self/fd/0.
The C program in the gist shows that the difference really is just
socketpair vs pipe2. If you run the version with pipe2 the open call
succeeds. Comment out pipe2 and uncomment socketpair, and the open
call fails.
Was this behavior change intentional?
What benefits are created by switching from pipe2 to socketpair?
> Basically, in Node 0.6, if you start a child_process with
> child_process.spawn, the pipe2 system call was used to create the
> pipes between parent and child.
> Now the socketpair call is used to create those fds.
> I'm not sure why that choice was made, but it has at least one bad
> effect: it breaks the ability to use "/dev/stdin" or "/proc/self/fd/0"
> on the child, at least on Linux.
> The gist shows a Node program that basically just spawns "cat
> /proc/self/fd/0", closes the pipe to the cat, and shows what the cat
> outputs. In 0.6.17 cat happily cats the empty stdin and exits 1. In
> 0.8.8 cat fails to open the /proc/self/fd/0.
> The C program in the gist shows that the difference really is just
> socketpair vs pipe2. If you run the version with pipe2 the open call
> succeeds. Comment out pipe2 and uncomment socketpair, and the open
> call fails.
> Was this behavior change intentional?
Yes.
> What benefits are created by switching from pipe2 to socketpair?
The ability to send file descriptors to the child process (which was
something you could do in v0.4 but not v0.6).
It's been brought up on the issue tracker a few times. A
straightforward workaround is to insert a pipe. E.g.:
So, I'm still trying to understand the implications of this change. Suppose I spawn "cat" and write to the stdin of the spawned process, then will the "cat" process not be able to read it?
On Wednesday, September 19, 2012 6:20:23 PM UTC-4, Ben Noordhuis wrote:
> On Wed, Sep 19, 2012 at 9:54 PM, David Glasser <gla...@meteor.com<javascript:>> > wrote: > > See https://gist.github.com/3751746 for details.
> > Basically, in Node 0.6, if you start a child_process with > > child_process.spawn, the pipe2 system call was used to create the > > pipes between parent and child.
> > This was changed (I believe) in this commit by indutny:
> > Now the socketpair call is used to create those fds.
> > I'm not sure why that choice was made, but it has at least one bad > > effect: it breaks the ability to use "/dev/stdin" or "/proc/self/fd/0" > > on the child, at least on Linux.
> > The gist shows a Node program that basically just spawns "cat > > /proc/self/fd/0", closes the pipe to the cat, and shows what the cat > > outputs. In 0.6.17 cat happily cats the empty stdin and exits 1. In > > 0.8.8 cat fails to open the /proc/self/fd/0.
> > The C program in the gist shows that the difference really is just > > socketpair vs pipe2. If you run the version with pipe2 the open call > > succeeds. Comment out pipe2 and uncomment socketpair, and the open > > call fails.
> > Was this behavior change intentional?
> Yes.
> > What benefits are created by switching from pipe2 to socketpair?
> The ability to send file descriptors to the child process (which was > something you could do in v0.4 but not v0.6).
> It's been brought up on the issue tracker a few times. A > straightforward workaround is to insert a pipe. E.g.:
On Thu, Sep 20, 2012 at 4:07 PM, dhruvbird <dhruvb...@gmail.com> wrote:
> Hello,
> So, I'm still trying to understand the implications of this change. Suppose
> I spawn "cat" and write to the stdin of the spawned process, then will the
> "cat" process not be able to read it?
On Thu, Sep 20, 2012 at 9:18 AM, Ben Noordhuis <i...@bnoordhuis.nl> wrote:
> On Thu, Sep 20, 2012 at 4:07 PM, dhruvbird <dhruvb...@gmail.com> wrote:
>> Hello,
>> So, I'm still trying to understand the implications of this change. Suppose
>> I spawn "cat" and write to the stdin of the spawned process, then will the
>> "cat" process not be able to read it?