Subject: Re: Possible bug relating to malloc()/realloc(), popen(), and read()
To: Vincent Stemen <netbsd@crel.us>
From: James Chacon <jmc@NetBSD.org>
List: port-i386
Date: 12/03/2004 09:29:37
On Thu, Dec 02, 2004 at 05:37:04PM -0600, Vincent Stemen wrote:
> On Thu, Dec 02, 2004 at 03:55:37PM -0600, James Chacon wrote:
> > On Thu, Dec 02, 2004 at 12:58:41PM -0600, Vincent Stemen wrote:
> > > On Thu, Dec 02, 2004 at 03:25:35PM +0100, Martin Husemann wrote:
> > > > Your program does not properly handle return values from read(). You need
> > > > to check -1 and errno == EAGAIN at least, if you don't read from straight
> > > > disk files.
> > > > 
> > > > Martin
> > > 
> > > It does check for -1.  According to the manual, EAGAIN is only for
> > > non-blocking I/O which I did not think applied in this case.
> > 
> > Actually I beleive you can get it on an interruption as well (say attaching
> > with the debugger). I don't recall if read does an automatic restart when
> > getting a signal or just returns EAGAIN.
> > 
> > James
> 
> I dug a bit further and, so far as I can tell according to the
> manuals, read(), along with several other I/O system calls, terminates
> with errno set to EINTR if interrupted before it is committed unless
> the SA_RESTART sigaction flag is set to request the restarting of
> pending calls.
> 

Ahh yes. So EINTR is the one you wanna check for possibly and simply retry.

James