Mailing List Archive

re: http://marc.theaimsgroup.com/?l=openssh-unix-dev&m=95669367427640&w=2 (fwd)
--
| "Bombay is 250ms from New York in the new world order" - Alan Cox
| Damien Miller - http://www.mindrot.org/
| Email: djm@mindrot.org (home) -or- djm@ibs.com.au (work)



---------- Forwarded message ----------
Date: Tue, 25 Apr 2000 19:55:56 -0600 (MDT)
From: Theo de Raadt <deraadt@cvs.openbsd.org>
To: djm@cvs.openbsd.org, markus@cvs.openbsd.org, provos@cvs.openbsd.org,
speno@isc.upenn.edu
Subject: re:
http://marc.theaimsgroup.com/?l=openssh-unix-dev&m=95669367427640&w=2

Index: clientloop.c
===================================================================
RCS file: /cvs/src/usr.bin/ssh/clientloop.c,v
retrieving revision 1.21
diff -u -r1.21 clientloop.c
--- clientloop.c 2000/04/19 07:05:48 1.21
+++ clientloop.c 2000/04/26 01:54:54
@@ -873,6 +873,8 @@
len = write(fileno(stdout), buffer_ptr(&stdout_buffer),
buffer_len(&stdout_buffer));
if (len <= 0) {
+ if (errno == EGAIN)
+ continue;
error("Write failed flushing stdout buffer.");
break;
}
@@ -884,6 +886,8 @@
len = write(fileno(stderr), buffer_ptr(&stderr_buffer),
buffer_len(&stderr_buffer));
if (len <= 0) {
+ if (errno == EGAIN)
+ continue;
error("Write failed flushing stderr buffer.");
break;
}
Re: http://marc.theaimsgroup.com/?l=openssh-unix-dev&m=95669367427640&w=2 (fwd) [ In reply to ]
On Thu, Apr 27, 2000 at 09:55:56AM +1000, Damien Miller wrote:
> + if (errno == EGAIN)
> + continue;

Just wondering, as my only OpenBSD box currently is down -
shouldn't that be EAGAIN instead of EGAIN?
At least I didn't find any reference of EGAIN under FreeBSD 2.2.8
and under Linux 2.2.14 (RedHat something if that matters) just
right now...


bye,
Harold

--
Someone should do a study to find out how many human life spans have
been lost waiting for NT to reboot.
Ken Deboy on Dec 24 1999 in comp.unix.bsd.freebsd.misc
Re: http://marc.theaimsgroup.com/?l=openssh-unix-dev&m=95669367427640&w=2 (fwd) [ In reply to ]
On Thu, Apr 27, 2000 at 03:50:50AM +0200, Harold Gutch wrote:
> On Thu, Apr 27, 2000 at 09:55:56AM +1000, Damien Miller wrote:
> > + if (errno == EGAIN)
> > + continue;
>
> Just wondering, as my only OpenBSD box currently is down -
> shouldn't that be EAGAIN instead of EGAIN?

Yes, it should, and that still doesn't fix the problem I'm seeing with scp.
My system trace seems to indicate that the problem occurs when a read() is
interrupted.
Re: http://marc.theaimsgroup.com/?l=openssh-unix-dev&m=95669367427640&w=2 (fwd) [ In reply to ]
On Thu, 27 Apr 2000, Harold Gutch wrote:

> On Thu, Apr 27, 2000 at 09:55:56AM +1000, Damien Miller wrote:
> > + if (errno == EGAIN)
> > + continue;
>
> Just wondering, as my only OpenBSD box currently is down -
> shouldn't that be EAGAIN instead of EGAIN?

Quite right



--
| "Bombay is 250ms from New York in the new world order" - Alan Cox
| Damien Miller - http://www.mindrot.org/
| Email: djm@mindrot.org (home) -or- djm@ibs.com.au (work)
Re: http://marc.theaimsgroup.com/?l=openssh-unix-dev&m=95669367427640&w=2 (fwd) [ In reply to ]
In situations like this, its usual that you would check for EINTR and
retry the read if that's what you got. (EAGAIN is what you get when you
do non-blocking IO and there was nothing to read.)

Cheers

Andrew

John P Speno wrote:
>
> On Thu, Apr 27, 2000 at 03:50:50AM +0200, Harold Gutch wrote:
> > On Thu, Apr 27, 2000 at 09:55:56AM +1000, Damien Miller wrote:
> > > + if (errno == EGAIN)
> > > + continue;
> >
> > Just wondering, as my only OpenBSD box currently is down -
> > shouldn't that be EAGAIN instead of EGAIN?
>
> Yes, it should, and that still doesn't fix the problem I'm seeing with scp.
> My system trace seems to indicate that the problem occurs when a read() is
> interrupted.
Re: http://marc.theaimsgroup.com/?l=openssh-unix-dev&m=95669367427640&w=2 (fwd) [ In reply to ]
John P Speno wrote:

> On Thu, Apr 27, 2000 at 03:50:50AM +0200, Harold Gutch wrote:
> > On Thu, Apr 27, 2000 at 09:55:56AM +1000, Damien Miller wrote:
> > > + if (errno == EGAIN)
> > > + continue;
> >
> > Just wondering, as my only OpenBSD box currently is down -
> > shouldn't that be EAGAIN instead of EGAIN?
>
> Yes, it should, and that still doesn't fix the problem I'm seeing with scp.
> My system trace seems to indicate that the problem occurs when a read() is
> interrupted.

I am curious about this thread:

Why don't relevant references to read/write use atomicio() in atomicio.c?

The usage should be clear.

result = read(fd, buf, num)

becomes
result = atomicio(read, fd, buf, num)


I have been bitten with similar interrupted system calls before.
To avoid these problems, read/write ought to be wrapped in something like
atomicio().
Most network read/write fall under this category.

One more tip I can think of.
Although openssh/scp doesn't use ferror() at all,
if we ever use ferror() [.if we use (FILE *), that is by assigning buffered
I/O data
structure to the file descriptor],
clearerr() needs to be called in order to clear incorrectly raised
error status due to the interrupted system call (!)
This is true for at least Solaris 2.5.1, and Solaris 7, etc..
This is so counter-intuitive and some well known code failed to
operate as the original authors intended for a long time due to this
`feature',
but people assumed the broken behavior for granted!

Happy Hacking,

Ishikawa