Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top