This is expected. While blocking in poll() and a signal arrives, poll will fail and errno will be set to EINTR
. You will get the same behavior for most system calls.
You can and should detect this (you now break out of the poll loop sooner too, as poll() will return when a signal is caught.)
while(!signalHandler.gotExitSignal()) {
switch (poll(&ufds[0], NUM_FDS, POLL_TIMEOUT)) {
case -1: {
if (errno == EINTR) {
continue;
}
throw std::runtime_error("poll error (-1)"); /* ABORT */
}
You would most likely want to set the SA_RESTART
flag for sigaction too.
killAction.sa_flags = SA_RESTART;
This will cause most system calls to NOT return an error when a signal is caught. Read the manpage for sigaction() for more info, and read the "Interruption of system calls and library functions by signal handlers" section in the man 7 signal.
Notably, poll() will still be interrupted(return an error immediately) by a signal regardless of setting the SA_RESTART
flag.