diff options
author | Tom Gundersen <teg@jklm.no> | 2014-02-22 20:19:49 +0100 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2014-02-22 21:24:36 +0100 |
commit | 0c2f9b84698b25e6065b9febd21486669a13870f (patch) | |
tree | 5ad727137610aeb1a9f56e01f3a9c82c6950d667 /src/network/networkd-manager.c | |
parent | 12e0f830f592ec4c6bb49ac7ae1e0e84f74105e3 (diff) |
networkd: handle SIGINT and SIGTERM
Diffstat (limited to 'src/network/networkd-manager.c')
-rw-r--r-- | src/network/networkd-manager.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index 55e5cafd00..c89adfba4f 100644 --- a/src/network/networkd-manager.c +++ b/src/network/networkd-manager.c @@ -38,6 +38,38 @@ const char* const network_dirs[] = { #endif NULL}; +static int dispatch_sigterm(sd_event_source *es, const struct signalfd_siginfo *si, void *userdata) { + Manager *m = userdata; + + assert(m); + + log_received_signal(LOG_INFO, si); + + sd_event_exit(m->event, 0); + return 0; +} + +static int setup_signals(Manager *m) { + sigset_t mask; + int r; + + assert(m); + + assert_se(sigemptyset(&mask) == 0); + sigset_add_many(&mask, SIGINT, SIGTERM, -1); + assert_se(sigprocmask(SIG_SETMASK, &mask, NULL) == 0); + + r = sd_event_add_signal(m->event, &m->sigterm_event_source, SIGTERM, dispatch_sigterm, m); + if (r < 0) + return r; + + r = sd_event_add_signal(m->event, &m->sigint_event_source, SIGINT, dispatch_sigterm, m); + if (r < 0) + return r; + + return 0; +} + int manager_new(Manager **ret) { _cleanup_manager_free_ Manager *m = NULL; int r; @@ -60,6 +92,10 @@ int manager_new(Manager **ret) { if (r < 0 && r != -ENOENT) /* TODO: drop when we can rely on kdbus */ return r; + r = setup_signals(m); + if (r < 0) + return r; + m->udev = udev_new(); if (!m->udev) return -ENOMEM; @@ -105,6 +141,8 @@ void manager_free(Manager *m) { udev_unref(m->udev); sd_bus_unref(m->bus); sd_event_source_unref(m->udev_event_source); + sd_event_source_unref(m->sigterm_event_source); + sd_event_source_unref(m->sigint_event_source); sd_event_unref(m->event); while ((network = m->networks)) |