Reputation: 3652
I want to handle if epoll_wait
was interrupted by any reason (for example by SIGINT)
while ( true ) {
n = epoll_wait ( epoll_fd, events, max_events, -1 );
if ( errno == EINTR ) {
...
}
}
But debugger did not even go to if
. Program was terminated in epoll_wait
. I've added some magick:
signal ( SIGINT, placebo );
while ( true ) {
n = epoll_wait ( epoll_fd, events, max_events, -1 );
if ( errno == EINTR ) {
...
}
}
And all works as expected. But this is ugly. What is the right way to let me handle any epoll_wait
's interrupt?
Upvotes: 1
Views: 1241
Reputation: 2559
You need to either handle signals or block them. If you just want to ignore EINTR I suggest blocking via the sigprocmask() or signal(signum, SIG_IGN) for a single-threaded process, or via pthread_sigmask() for a multithreaded process. If you want to actually do something, use sigaction() to install a handler.
Do not use signal() to set an actual handler. Its behavior varies across UNIX platforms. Read the manpages for details.
Upvotes: 2