Why dup()?

David Newall openssh at davidnewall.com
Sat Oct 14 16:37:22 AEDT 2017

On 14/10/17 07:44, Damien Miller wrote:
> On Fri, 13 Oct 2017, David Newall wrote:
>> On 13/10/17 16:22, Damien Miller wrote:
>>   > At a minimum, I think we'd have to dup2 a fd to /dev/null to
>>   > STDOUT_FILENO so writes to stdout (e.g. from ill-behaved
>>   > libraries) have somewhere to go.
>> Would that really be useful?  Output from Ill-behaved libraries,
>> written fd 1, already go to the same place.  Don't forget, dup does
>> not create a new file, it creates a duplicate handle to the same
>> file.  I'm proposing getting rid of the duplicate.
> Then what happens to stdout output between the time that the channel
> holding fd 1 closes and the time ssh exits?

The same thing that already happens: After the remote program closes 
stdout, any further attempt to write to that descriptor will fail; the 
program cannot continue to write to stdout after closing it; that is 
already the case.  The difference is that ssh will also close it's 
stdout; currently it keeps it open, which is an error.

More information about the openssh-unix-dev mailing list