aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2013-06-12 19:31:37 +0900
committerCedric Bail <cedric.bail@samsung.com>2013-06-14 16:38:18 +0900
commita3b3b5bd8e8a41501e8e22514dd0d381580a8f21 (patch)
treee5fb938044e60b061fa357d6f3b6674ed08d5d5a
parentevas/cserve2: catch more signals and exit nicely (diff)
downloadefl-a3b3b5bd8e8a41501e8e22514dd0d381580a8f21.tar.gz
evas/cserve2: Handle SIGINT properly
-rw-r--r--src/bin/evas/evas_cserve2_main_loop_linux.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/bin/evas/evas_cserve2_main_loop_linux.c b/src/bin/evas/evas_cserve2_main_loop_linux.c
index 590a8625f2..c29f9425de 100644
--- a/src/bin/evas/evas_cserve2_main_loop_linux.c
+++ b/src/bin/evas/evas_cserve2_main_loop_linux.c
@@ -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
_signalfd_setup(void)
{
sigset_t mask;
+ struct sigaction action;
sigemptyset(&mask);
sigaddset(&mask, SIGCHLD);
- sigaddset(&mask, SIGINT);
sigaddset(&mask, SIGTERM);
sigaddset(&mask, SIGQUIT);
sigaddset(&mask, SIGUSR1);
@@ -169,6 +177,11 @@ _signalfd_setup(void)
/* ignore SIGPIPE so it's handled by write() and send() as needed */
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;
}
@@ -768,9 +781,16 @@ cserve2_main_loop_run(void)
nfds = epoll_wait(epoll_fd, events, MAX_EPOLL_EVENTS, timeout);
if (nfds < 0)
{
- ERR("An error occurred when reading the epoll fd.");
- ERR("%s", strerror(errno));
- break;
+ if (errno == EINTR && !terminate)
+ {
+ INF("Ignoring interruption during epoll_wait.");
+ continue;
+ }
+ else
+ {
+ ERR("An error occurred when reading the epoll fd: %s.", strerror(errno));
+ break;
+ }
}
if (nfds == 0) // timeout occurred
{