[Vm-dev] Interrupted system call?

Andrew Gaylard ag at computer.org
Thu Feb 12 05:50:21 UTC 2009


On Wed, Feb 11, 2009 at 9:43 PM, Ian Piumarta <piumarta at speakeasy.net> wrote:
>
> On Feb 11, 2009, at 1:56 AM, Andrew Gaylard wrote:
>
>> - it does not specify that system calls should be restarted.
>> - it does not re-instate the handler (i.e. it assumes that kernel will).
>> - it does not in every case do the manual check for EINTR and restart,
>> as John mentioned in his post.
>>
>> My approach is to fix the former two, thus avoiding having to fix the
>> latter.
>
> Setting SA_RESTART does not guarantee that the kernel can (or even should)
> restart the call transparently; e.g., select() and poll() return EINTR even
> if the intervening signal has the restart flag set.  Section 10.5 of
> Advanced Programming in the UNIX Environment (Stevens and Rago) explains
> quantitatively some issues in handling EINTR, has a table of the behaviours
> supported among a few flavours of Unix, and mentions a few inconsistencies.

You're absolutely right.  Section 5.9 of Unix Network Programming (Stevens,
Fenner, & Rudoff) is even more explicit:

*Some* kernels automatically restart *some* interrupted system calls.
For portability, when we write a program that catches signals (most
concurrent servers catch SIGCHLD), we must be prepared for slow
system calls to return EINTR.

(Their emphasis, not mine). So we still have to check each time for EINTR
and loop if necessary.

Sorry about that.

- Andrew


More information about the Vm-dev mailing list