Interrupted system calls

Interrupted system calls

Post by Andrew Zahra (Telec » Tue, 07 Apr 1992 07:43:34



I am doing some work with internet domain sockets. Occaisonally I get an
"interrupted system call" error (EINTR). What am I supposed to do about this?
Just try again?


Telecom Australia              
Customised Software
Solutions Centre

Phone:  +61 42 211111           Snail:  Telecom CSSC
Fax:    +61 42 291021                   C/- Illawarra Technology Centre
                                        PO Box 2112
                                        Wollongong 2500

 
 
 

Interrupted system calls

Post by Jonathan I. Kame » Tue, 07 Apr 1992 23:46:14



   I am doing some work with internet domain sockets. Occaisonally I
   get an "interrupted system call" error (EINTR). What am I supposed
   to do about this?  Just try again?

In most cases, yes.

However, it's difficult to answer for sure without knowing more about
your program.... What's CAUSING the EINTR?  What signals are you
using?  What system calls are being interrupted?

There are problems with just restarting in some cases.  For example, I
believe it's possible for a write() to be interrupted after part of
the data you give it has already been written, and I don't think
there's any way to know how much data was written before the interrupt
(ugh!).

--

MIT Information Systems/Athena              Moderator, news.answers
    (Send correspondence related to the news.answers newsgroup
        {and ONLY correspondence related to the newsgroup}


 
 
 

Interrupted system calls

Post by Dan Bernste » Wed, 08 Apr 1992 07:58:13



Quote:> There are problems with just restarting in some cases.  For example, I
> believe it's possible for a write() to be interrupted after part of
> the data you give it has already been written, and I don't think
> there's any way to know how much data was written before the interrupt
> (ugh!).

On broken systems, and in stupid cases, yes. On working systems write()
will always return the number of bytes written, if that number is
positive. (Yes, this is part of my definition of ``working''; yes, there
exist systems which work in this respect.)

---Dan

 
 
 

Interrupted system calls

Post by Jonathan I. Kame » Wed, 08 Apr 1992 12:09:50


   On broken systems, and in stupid cases, yes. On working systems write()
   will always return the number of bytes written, if that number is
   positive. (Yes, this is part of my definition of ``working''; yes, there
   exist systems which work in this respect.)

Code that is attempting to be portable does not rely on functionality
that is known not to exist on some machines (in this case, a large
number of machines).

If you want to write code that will functional properly only on
systems that you consider "workins" ones, then by all means, don't
deal with the possibility of partial, interrupted write()s.

If, on the other hand, you want your code to be as portable as
possible and therefore used by as many people as possible, it should
be able to deal with the possibility of brain-damage in the
environment.  At they very least, put in an undocumented set of
#ifdef's to deal with the possibility, so that when people complain
that something's breaking, you can tell them, "Put this -D in the
Makefile and send a flame to your vendor."

--

MIT Information Systems/Athena              Moderator, news.answers
    (Send correspondence related to the news.answers newsgroup
        {and ONLY correspondence related to the newsgroup}

 
 
 

Interrupted system calls

Post by John Chambe » Wed, 22 Apr 1992 11:21:05




> > There are problems with just restarting in some cases.  For example, I
> > believe it's possible for a write() to be interrupted after part of
> > the data you give it has already been written, and I don't think
> > there's any way to know how much data was written before the interrupt
> > (ugh!).

> On broken systems, and in stupid cases, yes. On working systems write()
> will always return the number of bytes written, if that number is
> positive. (Yes, this is part of my definition of ``working''; yes, there
> exist systems which work in this respect.)

While this sounds useful, it appears to be contrary to TFM,  which  on
this Sys/VR4 system (like most others I've seen) states in write(2):

        Upon successful completion the number of bytes actually written is
        returned.  Otherwise, -1 is returned, and errno is set to indicate
        the error.

This follows the usual Unix convention  that  errno  is  only  set  on
failure,  and remains unchanged on success.  It appears that there are
only two outcomes supported by the manual:

        value >= 0 and errno unchanged.
        value = -1 and errno changed.

There is no room here for a non-negative  byte  count  being  returned
when errno is set to EINTR.  It sure would be useful. But if the value
is positive, how is the program to know that the value of errno is  to
be tested?  TFM doesn't seem to admit this as a possibility, much less
say how you might detect that it has happened.

 
 
 

Interrupted system calls

Post by Dan Bernste » Thu, 23 Apr 1992 16:46:08




> > On working systems write()
> > will always return the number of bytes written, if that number is
> > positive.
> While this sounds useful, it appears to be contrary to TFM,  which  on
> this Sys/VR4 system (like most others I've seen) states in write(2):
  [ ... ]
> There is no room here for a non-negative  byte  count  being  returned
> when errno is set to EINTR.

That's correct. We weren't talking about any such behavior. If the
number of bytes written is positive then write() has, by definition,
succeeded, and in that case if the kernel returns -1 or sets errno then
it is misdesigned. There are no two ways about this: a working operating
system simply does not throw I/O away! (This is a lesser sin when it's a
human generating the I/O---for instance, when the OS flushes the
keyboard buffer---but still a sin.)

Some people seem to believe that write() *must* return -1/EINTR if the
I/O was interrupted---I've even seen code which assumes this instead of
handling signals properly. But that's the wrong way around. If write()
returns -1 then, on a working system, you can be sure that no bytes were
written successfully; if errno shows up as EINTR you can then conclude
that write() failed because of a signal rather than an I/O error. The
converse statement is false. There are cases, on working systems, when
write() will be interrupted by a signal but will return a positive
number. That's how it should be, if some bytes were written before the
signal. Again: a working system simply does not throw I/O away!

---Dan

 
 
 

Interrupted system calls

Post by Rich Sa » Thu, 30 Apr 1992 05:03:49


Quote:>This follows the usual Unix convention  that  errno  is  only  set  on
>failure,  and remains unchanged on success.

No -- the Unix convention is "set errno on failure"; in case of success
errno is unspecified.
        /r$