summaryrefslogtreecommitdiff
path: root/src/network/networkd-manager.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-07-07 23:11:03 +0200
committerLennart Poettering <lennart@poettering.net>2014-07-07 23:11:03 +0200
commit186fe1db20902b6542cee58ba499ced914d687a8 (patch)
tree7ea2225adb6039e7dfec77f3d3bc7133997c368b /src/network/networkd-manager.c
parentb9e7a9d870ac41d4db954edd52a1f5dd7d153389 (diff)
networkd: simplify signal handling of SIGTERM/SIGINT
sd-event makes handling SIGTERM/SIGINT a lot easier than it used to, let's make use of this
Diffstat (limited to 'src/network/networkd-manager.c')
-rw-r--r--src/network/networkd-manager.c39
1 files changed, 3 insertions, 36 deletions
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index c1d50128a5..46b803fee5 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -43,38 +43,6 @@ 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;
-}
-
static int setup_default_address_pool(Manager *m) {
AddressPool *p;
int r;
@@ -120,6 +88,9 @@ int manager_new(Manager **ret) {
sd_event_set_watchdog(m->event, true);
+ sd_event_add_signal(m->event, NULL, SIGTERM, NULL, NULL);
+ sd_event_add_signal(m->event, NULL, SIGINT, NULL, NULL);
+
r = sd_rtnl_open(&m->rtnl, 3, RTNLGRP_LINK, RTNLGRP_IPV4_IFADDR,
RTNLGRP_IPV6_IFADDR);
if (r < 0)
@@ -129,10 +100,6 @@ 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;
-
/* udev does not initialize devices inside containers,
* so we rely on them being already initialized before
* entering the container */