evas/cserve2: Handle SIGINT properly

This commit is contained in:
Jean-Philippe Andre 2013-06-12 19:31:37 +09:00 committed by Cedric Bail
parent 338218109b
commit a3b3b5bd8e
1 changed files with 24 additions and 4 deletions

View File

@ -143,14 +143,22 @@ _signalfd_handler(int fd, Fd_Flags flags EINA_UNUSED, void *data EINA_UNUSED)
} }
} }
static void
_sigint_handler(int id, siginfo_t *info EINA_UNUSED, void *data EINA_UNUSED)
{
if (id != SIGINT) return;
DBG("Received SIGINT. Honoring request.");
terminate = EINA_TRUE;
}
static int static int
_signalfd_setup(void) _signalfd_setup(void)
{ {
sigset_t mask; sigset_t mask;
struct sigaction action;
sigemptyset(&mask); sigemptyset(&mask);
sigaddset(&mask, SIGCHLD); sigaddset(&mask, SIGCHLD);
sigaddset(&mask, SIGINT);
sigaddset(&mask, SIGTERM); sigaddset(&mask, SIGTERM);
sigaddset(&mask, SIGQUIT); sigaddset(&mask, SIGQUIT);
sigaddset(&mask, SIGUSR1); sigaddset(&mask, SIGUSR1);
@ -169,6 +177,11 @@ _signalfd_setup(void)
/* ignore SIGPIPE so it's handled by write() and send() as needed */ /* ignore SIGPIPE so it's handled by write() and send() as needed */
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
action.sa_sigaction = _sigint_handler;
action.sa_flags = SA_SIGINFO;
sigemptyset(&action.sa_mask);
sigaction(SIGINT, &action, NULL);
return signal_fd; return signal_fd;
} }
@ -768,10 +781,17 @@ cserve2_main_loop_run(void)
nfds = epoll_wait(epoll_fd, events, MAX_EPOLL_EVENTS, timeout); nfds = epoll_wait(epoll_fd, events, MAX_EPOLL_EVENTS, timeout);
if (nfds < 0) if (nfds < 0)
{ {
ERR("An error occurred when reading the epoll fd."); if (errno == EINTR && !terminate)
ERR("%s", strerror(errno)); {
INF("Ignoring interruption during epoll_wait.");
continue;
}
else
{
ERR("An error occurred when reading the epoll fd: %s.", strerror(errno));
break; break;
} }
}
if (nfds == 0) // timeout occurred if (nfds == 0) // timeout occurred
{ {
timeout = -1; timeout = -1;