ssh client is setting O_NONBLOCK on a pipe shared with other processes

Alex Bligh alex at alex.org.uk
Tue Sep 17 07:12:14 AEST 2019


> On 16 Sep 2019, at 16:06, Doug Graham <edougra at gmail.com> wrote:
> 
>> Case in point; EAGAIN can come if you give your fd to another process
>> and continue using it yourself.
> 
>> Short counts; It is documented behavior that read() and write() may
>> return short counts. It is not documented why, so you can not make
>> any assumptions.
> 
> You might be right about short counts but if you're right about
> EAGAIN, there are
> bugs everywhere.  My first attempt at working around my "make: write error"
> failure was to pipe make into cat or tee, eg: "make | tee make.log".  But that
> caused both cat and tee to fail with EAGAIN.  So they have the same "bug" as
> make.  Also note that make is just calling printf normally and then
> just before exiting,
> it calls ferror(stdout) to see if any error occurred when it
> previously wrote to stdout.
> ferror()  is returning true.  So now the bug has moved into the C library.

Dumb question: shouldn't whatever is calling fork() (here 'make' I believe)
be dup()'ing the FDs just in case the called program does something odd
with them like set O_NONBLOCK? That's what I've always done before
fork(), and I believe what the venerable Mr Stevens recommends.

-- 
Alex Bligh






More information about the openssh-unix-dev mailing list