summaryrefslogtreecommitdiff
path: root/manager.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-01-27 04:36:30 +0100
committerLennart Poettering <lennart@poettering.net>2010-01-27 04:36:30 +0100
commitb9cd2ec1c8be840e6271265d983e66d9907ecbe4 (patch)
treed0d5b1583ff44c4284b1e0fbf5dbfaa4dfc7efe1 /manager.c
parentacbb02252a38214ecba3aa8a5c9b3669f9c9317e (diff)
exit cleanly on SIGINT
Diffstat (limited to 'manager.c')
-rw-r--r--manager.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/manager.c b/manager.c
index e9ae40ca74..a598f1241d 100644
--- a/manager.c
+++ b/manager.c
@@ -43,6 +43,7 @@ Manager* manager_new(void) {
assert_se(sigemptyset(&mask) == 0);
assert_se(sigaddset(&mask, SIGCHLD) == 0);
+ assert_se(sigaddset(&mask, SIGINT) == 0);
assert_se(sigprocmask(SIG_SETMASK, &mask, NULL) == 0);
m->signal_watch.type = WATCH_SIGNAL_FD;
@@ -977,7 +978,7 @@ static int manager_dispatch_sigchld(Manager *m) {
return 0;
}
-static int manager_process_signal_fd(Manager *m) {
+static int manager_process_signal_fd(Manager *m, bool *quit) {
ssize_t n;
struct signalfd_siginfo sfsi;
bool sigchld = false;
@@ -996,8 +997,16 @@ static int manager_process_signal_fd(Manager *m) {
return -errno;
}
- if (sfsi.ssi_signo == SIGCHLD)
+ switch (sfsi.ssi_signo) {
+
+ case SIGCHLD:
sigchld = true;
+ break;
+
+ case SIGINT:
+ *quit = true;
+ return 0;
+ }
}
if (sigchld)
@@ -1006,7 +1015,7 @@ static int manager_process_signal_fd(Manager *m) {
return 0;
}
-static int process_event(Manager *m, struct epoll_event *ev) {
+static int process_event(Manager *m, struct epoll_event *ev, bool *quit) {
int r;
Watch *w;
@@ -1023,7 +1032,7 @@ static int process_event(Manager *m, struct epoll_event *ev) {
if (ev->events != POLLIN)
return -EINVAL;
- if ((r = manager_process_signal_fd(m)) < 0)
+ if ((r = manager_process_signal_fd(m, quit)) < 0)
return r;
break;
@@ -1060,6 +1069,7 @@ static int process_event(Manager *m, struct epoll_event *ev) {
int manager_loop(Manager *m) {
int r;
+ bool quit = false;
assert(m);
@@ -1077,8 +1087,12 @@ int manager_loop(Manager *m) {
return -errno;
}
- for (i = 0; i < n; i++)
- if ((r = process_event(m, events + i)) < 0)
+ for (i = 0; i < n; i++) {
+ if ((r = process_event(m, events + i, &quit)) < 0)
return r;
+
+ if (quit)
+ return 0;
+ }
}
}