Why dup()?

David Newall
2017-10-13T07:24:50Z

On 12/10/17 12:54, Clark Wang wrote:
> How did you hit the problem? "ssh host echo hello | cat" works
fine
> for me.

That's because ssh exited, not because of EOF.

Consider the following:

 ?? ssh localhost 'exec cat > /dev/null' | { read l; echo ${l:-EOF};
}

One should see "EOF" immediately (for values of immediate that include
startup latency), but that's not what happens.

I did have a better example.? When ssh was run with debug output, it
showed ssh drain and close output when the remote end closed it's
output.? Owing to ssh having two copies of the output descriptor, the
downstream program did not see that EOF (it's not EOF until both file
descriptors are closed.)? Now, irritatingly, I can't reproduce that.?
Now, the remote program closes its output, the sshd parent closes its
end of that pipe, but ssh smugly sits there, keeping output (both
copies) open until the remote program exits.? Clearly there is more
going on that just two descriptors to the same output pipe.

It's wrong; ssh should not absorb EOF.