8

Is there any reasonably complete list of which functions in POSIX are interrupted with EINTR when a signal is received or handled, even if there is no signal handler or if the handler was installed with SA_RESTART? Some examples:

  • select
  • nanosleep
  • etc.
R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711

3 Answers3

2

tcsetattr is also not restartable, at least in Linux 2.6.18

G Back
  • 21
  • 2
1

If anyone wonders, the manpage for signal(7) has more detail on what is and what isn't restarted:

V0ldek
  • 9,623
  • 1
  • 26
  • 57
1

POSIX says:

If the signal-catching function executes a return statement, the behavior of the interrupted function shall be as described individually for that function, except as noted for unsafe functions.

So, either you look through all functions individually or filter your man pages for EINTR and POSIX. I did the latter and got:

accept, aio_suspend, catclose, catgets, chmod, chown, clock_nanosleep, close, closedir, connect, dup, errno, exec, fallocate, fchdir, fchmod, fchown, fclose, fcntl, fflush, fgetc, fgetwc, fopen, fork, fputc, fputwc, freopen, fseek, fsetpos, fsync, ftruncate, getgrent, getgrgid, getgrnam, getmsg, getpwent, getpwnam, getpwuid, ioctl, lchown, lio_listio, lockf, mq_open, mq_receive, mq_send, msgop, msgrcv, msgsnd, nanosleep, open, pause, pclose, poll, posix_fallocate, posix_mem_offset, posix_trace_create, posix_trace_get_filter, posix_trace_getnext_event, posix_trace_open, posix_trace_start, posix_typed_mem_get_info, posix_typed_mem_open, printf, pthread_atfork, pthread_attr_getdetachstate, pthread_attr_getguardsize, pthread_attr_getinheritsched, pthread_attr_getschedparam, pthread_attr_getschedpolicy, pthread_attr_getscope, pthread_attr_getstack, pthread_attr_getstackaddr, pthread_attr_getstacksize, pthread_attr_init, pthread_barrier_init, pthread_barrier_wait, pthread_barrierattr_getpshared, pthread_barrierattr_init, pthread_cancel, pthread_cleanup_push, pthread_cond_init, pthread_cond_signal, pthread_cond_wait, pthread_condattr_getclock, pthread_condattr_getpshared, pthread_condattr_init, pthread_create, pthread_detach, pthread_equal, pthread_getconcurrency, pthread_getschedparam, pthread_getspecific, pthread_join, pthread_key_create, pthread_key_delete, pthread_kill, pthread_mutex_getprioceiling, pthread_mutex_init, pthread_mutex_lock, pthread_mutex_timedlock, pthread_mutexattr_getprioceiling, pthread_mutexattr_getprotocol, pthread_mutexattr_getpshared, pthread_mutexattr_gettype, pthread_mutexattr_init, pthread_once, pthread_rwlock_init, pthread_rwlock_rdlock, pthread_rwlock_timedrdlock, pthread_rwlock_timedwrlock, pthread_rwlock_unlock, pthread_rwlock_wrlock, pthread_rwlockattr_getpshared, pthread_rwlockattr_init, pthread_self, pthread_setschedprio, pthread_spin_init, pthread_spin_lock, pthread_spin_unlock, pthread_testcancel, putmsg, read, recv, recvfrom, recvmsg, scanf, select, select_tut, sem_open, sem_timedwait, sem_wait, semop, send, sendmsg, sendto, shm_open, sigaction, siginterrupt, sigpause, sigprocmask, sigset, sigsuspend, sigvec, sigwaitinfo, statfs, statvfs, system, tcdrain, tcsetattr, tmpfile, truncate, ualarm, usleep, wait, waitid and write

sl0815
  • 567
  • 1
  • 9
  • 21
  • 2
    But some of these always return -1 with `EINTR` if a signal occurs, and others return -1 with `EINTR` only when there's a signal handler installed without `SA_RESTART`. My question is about distinguishing these two cases. – R.. GitHub STOP HELPING ICE Mar 25 '11 at 02:28
  • 1
    All of the above functions, except msgop, semop, sem*wait, and select, are restarted if a signal with SA_RESTART is received and the signal handler returns. msgop, semop, sem*wait always return -1 with EINTR and the behaviour of select is implementation-defined (may fail or may be restarted). – sl0815 Mar 25 '11 at 12:13
  • Do you have a reference? I can't find if/where it's specified in POSIX. – R.. GitHub STOP HELPING ICE Mar 25 '11 at 12:52
  • 2
    [link](http://pubs.opengroup.org/onlinepubs/9699919799/functions/sigaction.html) and [link](http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04) – sl0815 Mar 25 '11 at 14:25
  • 1
    Since Linux is a very popular implementation, it is probably worth noting that it does not strictly match POSIX in this area. https://stackoverflow.com/questions/4959524/when-to-check-for-eintr-and-repeat-the-function-call#comment46931524_4960077 – sourcejedi Mar 22 '18 at 19:56