signal(7) for Linux lists
accept
connect
fcntl
flock
futex
ioctl
open
read
readv
recv
recvfrom
recvmsg
send
sendmsg
sendto
wait
wait3
wait4
waitid
waitpid
write
writev
as possibly interruptible (EINTR) by no-SA_RESTART handlers and
setsockopt
accept
recv
recvfrom
recvmsg
connect
send
sendto
sendmsg
pause
sigsuspend
sigtimedwait
sigwaitinfo
epoll_wait
epoll_pwait
poll
ppoll
select
lect
msgrcv
msgsnd
semop
semtimedop
clock_nanosleep
nanosleep
read
io_getevents
sleep
as EINTR-interruptible, even by SA_RESTART handlers.
Furthermore, it lists:
setsockopt
accept
recv
recvfrom
recvmsg
connect
send
sendto
sendmsg
epoll_wait
epoll_pwait
semop
semtimedop
sigtimedwait
sigwaitinfo
read
futex
msgrcv
msgsnd
nanosleep
as EINTR-interruptible by a stopping signal + SIGCONT
, and says this particular behavior is Linux-specific and not sanctioned by POSIX.1
.
Apart from these, especially if the function's specification doesn't list EINTR
, you shouldn't get EINTR
.
If you don't trust the system to honor it, you can try bombarding a loop with your suspected system function by SIGSTOP
/SIGCONT
+a signal with a no-SA_RESTART
no-op handler and see if you can elicit an EINTR.
I tried that with:
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
static void chld(int Sig)
{
int status;
if(0>wait(&status))
_exit(1);
if(!WIFEXITED(status)){
//this can only interrupt an AS-safe block
assert(WIFSIGNALED(status) && WTERMSIG(status) == SIGALRM);
puts("OK");
exit(0);
} else {
switch(WEXITSTATUS(status)){
case 1: puts("FAIL"); break;
case 2: puts("EINTR"); break;
}
}
exit(0);
}
static void nop(int Sig)
{
}
int main()
{
sigset_t full;
sigfillset(&full);
sigaction(SIGCHLD, &(struct sigaction){ .sa_handler=chld, .sa_mask=full, .sa_flags=0 } , 0);
sigaction(SIGUSR1, &(struct sigaction){ .sa_handler=nop, .sa_mask=full, .sa_flags=0 } , 0);
pid_t p;
if(0>(p=fork())) { perror(0); return 1; }
if(p!=0){
//bombard it with SIGSTOP/SIGCONT/SIGUSR1
for(;;){
usleep(1); kill(p, SIGSTOP); kill(p, SIGCONT); kill(p, SIGUSR1);
}
}else{
sigaction(SIGCHLD, &(struct sigaction){ .sa_handler=SIG_DFL }, 0);
if(0>alarm(1))
return 1;
for(;;){
#if 1
/*not interruptible*/
if(0>access("/dev/null", R_OK)){
if(errno==EINTR)
return 2;
perror(0);
return 1;
}
#else
int fd;
unlink("fifo");
if(0>mkfifo("fifo",0600))
return 1;
/*interruptible*/
if(0>(fd=open("fifo", O_RDONLY|O_CREAT, 0600))){
if(errno==EINTR)
return 2;
perror(0);
return 1;
}
close(fd);
#endif
}
}
return 0;
}
and unlink
and access
definitely appear to be EINTR-uninterruptible (in compliance with their spec), which means an EINTR
-retry loop around them would be unnecessary.
EINTR
andEAGAIN
mean different things. I would recommend always writing code to handleEINTR
. If you getEAGAIN
when you didn't ask for it, there's a serious logic error either in your program or in the kernel. – Dull