1

I am using select in one of my OSX programs to watch some file descriptors. I encountered the issue with child processes on Linux that select may fail with errno set to EINTR. On Linux I have encountered this using

struct sigaction sa;
::memset(&sa, 0, sizeof(sa));
sa.sa_handler = child_death_signal_handler;
sa.sa_flags = SA_RESTART;
sigaction(SIGCHLD, &sa, NULL);

Setting the SA_RESTART flag which will eradicate the issue on Linux. On OSX however, SA_RESTART is mentioned in the manpages, but it seems to have zero effect, as my read functions, etc, still fail with EINTR as errno.

Is there some way to make this work in OSX also?

Nidhoegger
  • 4,973
  • 4
  • 36
  • 81
  • 1
    Possible duplicate of [Which functions are interrupted by signals even with SA\_RESTART?](http://stackoverflow.com/questions/5405297/which-functions-are-interrupted-by-signals-even-with-sa-restart) – Jean-Baptiste Yunès May 17 '17 at 10:57

2 Answers2

1

For Linux, SA_RESTART has no effect on select(2). See the manpage for signal(7):

The following interfaces are never restarted after being interrupted
by  a  signal  handler,  regardless  of  the  use  of SA_RESTART;
they always fail with the error EINTR when interrupted by a signal
handler:
...
* File descriptor multiplexing interfaces: epoll_wait(2),
  epoll_pwait(2), poll(2), ppoll(2), select(2), and pselect(2).
  • Quote from OP: "I am using select in one of my OSX programs to watch some file descriptors." – Nidhoegger Feb 02 '18 at 18:57
  • Finish reading the OP: "I encountered the issue with child processes on Linux that select may fail with errno set to EINTR. On Linux I have encountered this using...Setting the SA_RESTART flag which will eradicate the issue on Linux." This is false. – Frederick Ollinger Feb 03 '18 at 20:26
  • Thank you, please tell it Debian that they should change behaviour in their distribution :). – Nidhoegger Feb 07 '18 at 14:45
1

It appears that SA_RESTART does not have any effect on accept() if the calling ("accepting") thread is stopped/resumed with a signal.

Don Cruickshank
  • 5,641
  • 6
  • 48
  • 48