From: Lennart Poettering Date: Tue, 24 Apr 2018 16:14:25 +0000 (+0200) Subject: logind: terminate cleanly on SIGTERM/SIGINT X-Git-Tag: v239~339^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fcfa765d189f4a9b0e30aa448cf0cd3d41a6a2a6;p=thirdparty%2Fsystemd.git logind: terminate cleanly on SIGTERM/SIGINT Let's properly terminate on SIGTERM or SIGINT. Previously we'd just rely on the implicit process clean-up logic on UNIX. By shutting down properly on SIGTERM/SIGINT we make it easier to track down memory leaks by employing valgrind. --- diff --git a/src/login/logind.c b/src/login/logind.c index 410f6074c6e..b0fd3f9cc57 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -69,6 +69,14 @@ static int manager_new(Manager **ret) { if (r < 0) return r; + r = sd_event_add_signal(m->event, NULL, SIGINT, NULL, NULL); + if (r < 0) + return r; + + r = sd_event_add_signal(m->event, NULL, SIGTERM, NULL, NULL); + if (r < 0) + return r; + (void) sd_event_set_watchdog(m->event, true); manager_reset_config(m); @@ -1084,8 +1092,6 @@ static int manager_startup(Manager *m) { assert(m); - assert_se(sigprocmask_many(SIG_SETMASK, NULL, SIGHUP, -1) >= 0); - r = sd_event_add_signal(m->event, NULL, SIGHUP, manager_dispatch_reload_signal, m); if (r < 0) return log_error_errno(r, "Failed to register SIGHUP handler: %m"); @@ -1224,6 +1230,8 @@ int main(int argc, char *argv[]) { mkdir_label("/run/systemd/users", 0755); mkdir_label("/run/systemd/sessions", 0755); + assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGHUP, SIGTERM, SIGINT, -1) >= 0); + r = manager_new(&m); if (r < 0) { log_error_errno(r, "Failed to allocate manager object: %m");