diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index f01d771f9b..0e06a16a24 100644 --- a/src/hostname/hostnamed.c +++ b/src/hostname/hostnamed.c @@ -14,6 +14,7 @@ #include "bus-log-control-api.h" #include "bus-polkit.h" #include "constants.h" +#include "daemon-util.h" #include "env-file-label.h" #include "env-file.h" #include "env-util.h" @@ -1733,6 +1734,10 @@ static int run(int argc, char *argv[]) { if (r < 0) return r; + r = sd_notify(false, NOTIFY_READY); + if (r < 0) + log_warning_errno(r, "Failed to send readiness notification, ignoring: %m"); + r = bus_event_loop_with_idle( context.event, context.bus, diff --git a/src/import/importd.c b/src/import/importd.c index 8bc8a32866..3321155e84 100644 --- a/src/import/importd.c +++ b/src/import/importd.c @@ -12,6 +12,7 @@ #include "bus-polkit.h" #include "common-signal.h" #include "constants.h" +#include "daemon-util.h" #include "env-util.h" #include "fd-util.h" #include "float.h" @@ -1332,18 +1333,6 @@ static bool manager_check_idle(void *userdata) { return hashmap_isempty(m->transfers); } -static int manager_run(Manager *m) { - assert(m); - - return bus_event_loop_with_idle( - m->event, - m->bus, - "org.freedesktop.import1", - DEFAULT_EXIT_USEC, - manager_check_idle, - m); -} - static void manager_parse_env(Manager *m) { int r; @@ -1394,7 +1383,17 @@ static int run(int argc, char *argv[]) { if (r < 0) return r; - r = manager_run(m); + r = sd_notify(false, NOTIFY_READY); + if (r < 0) + log_warning_errno(r, "Failed to send readiness notification, ignoring: %m"); + + r = bus_event_loop_with_idle( + m->event, + m->bus, + "org.freedesktop.import1", + DEFAULT_EXIT_USEC, + manager_check_idle, + m); if (r < 0) return log_error_errno(r, "Failed to run event loop: %m"); diff --git a/src/locale/localed.c b/src/locale/localed.c index 8ce8c0d08f..cf88da37ad 100644 --- a/src/locale/localed.c +++ b/src/locale/localed.c @@ -15,6 +15,7 @@ #include "bus-polkit.h" #include "bus-unit-util.h" #include "constants.h" +#include "daemon-util.h" #include "kbd-util.h" #include "localed-util.h" #include "macro.h" @@ -647,26 +648,24 @@ static int run(int argc, char *argv[]) { if (r < 0) return r; - assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGTERM, SIGINT, -1) >= 0); - r = sd_event_default(&event); if (r < 0) return log_error_errno(r, "Failed to allocate event loop: %m"); (void) sd_event_set_watchdog(event, true); - r = sd_event_add_signal(event, NULL, SIGINT, NULL, NULL); + r = sd_event_set_signal_exit(event, true); if (r < 0) - return log_error_errno(r, "Failed to install SIGINT handler: %m"); - - r = sd_event_add_signal(event, NULL, SIGTERM, NULL, NULL); - if (r < 0) - return log_error_errno(r, "Failed to install SIGTERM handler: %m"); + return log_error_errno(r, "Failed to install SIGINT/SIGTERM handlers: %m"); r = connect_bus(&context, event, &bus); if (r < 0) return r; + r = sd_notify(false, NOTIFY_READY); + if (r < 0) + log_warning_errno(r, "Failed to send readiness notification, ignoring: %m"); + r = bus_event_loop_with_idle(event, bus, "org.freedesktop.locale1", DEFAULT_EXIT_USEC, NULL, NULL); if (r < 0) return log_error_errno(r, "Failed to run event loop: %m"); diff --git a/src/machine/machined.c b/src/machine/machined.c index 4e830a4bc2..108fe0327b 100644 --- a/src/machine/machined.c +++ b/src/machine/machined.c @@ -320,17 +320,6 @@ static bool check_idle(void *userdata) { return hashmap_isempty(m->machines); } -static int manager_run(Manager *m) { - assert(m); - - return bus_event_loop_with_idle( - m->event, - m->bus, - "org.freedesktop.machine1", - DEFAULT_EXIT_USEC, - check_idle, m); -} - static int run(int argc, char *argv[]) { _cleanup_(manager_unrefp) Manager *m = NULL; int r; @@ -363,16 +352,20 @@ static int run(int argc, char *argv[]) { if (r < 0) return log_error_errno(r, "Failed to fully start up daemon: %m"); - log_debug("systemd-machined running as pid "PID_FMT, getpid_cached()); r = sd_notify(false, NOTIFY_READY); if (r < 0) log_warning_errno(r, "Failed to send readiness notification, ignoring: %m"); - r = manager_run(m); + r = bus_event_loop_with_idle( + m->event, + m->bus, + "org.freedesktop.machine1", + DEFAULT_EXIT_USEC, + check_idle, m); + if (r < 0) + return log_error_errno(r, "Failed to run main loop: %m"); - (void) sd_notify(false, NOTIFY_STOPPING); - log_debug("systemd-machined stopped as pid "PID_FMT, getpid_cached()); - return r; + return 0; } DEFINE_MAIN_FUNCTION(run); diff --git a/src/portable/portabled.c b/src/portable/portabled.c index 7c2ddd90ef..d4a01fa53b 100644 --- a/src/portable/portabled.c +++ b/src/portable/portabled.c @@ -122,17 +122,6 @@ static bool check_idle(void *userdata) { return !m->operations; } -static int manager_run(Manager *m) { - assert(m); - - return bus_event_loop_with_idle( - m->event, - m->bus, - "org.freedesktop.portable1", - DEFAULT_EXIT_USEC, - check_idle, m); -} - static int run(int argc, char *argv[]) { _cleanup_(manager_unrefp) Manager *m = NULL; int r; @@ -162,16 +151,20 @@ static int run(int argc, char *argv[]) { if (r < 0) return log_error_errno(r, "Failed to fully start up daemon: %m"); - log_debug("systemd-portabled running as pid " PID_FMT, getpid_cached()); r = sd_notify(false, NOTIFY_READY); if (r < 0) log_warning_errno(r, "Failed to send readiness notification, ignoring: %m"); - r = manager_run(m); + r = bus_event_loop_with_idle( + m->event, + m->bus, + "org.freedesktop.portable1", + DEFAULT_EXIT_USEC, + check_idle, m); + if (r < 0) + return log_error_errno(r, "Failed to run main loop: %m"); - (void) sd_notify(false, NOTIFY_STOPPING); - log_debug("systemd-portabled stopped as pid " PID_FMT, getpid_cached()); - return r; + return 0; } DEFINE_MAIN_FUNCTION(run); diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index 4123152d93..09a3734aeb 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -18,6 +18,7 @@ #include "bus-internal.h" #include "bus-label.h" #include "bus-util.h" +#include "daemon-util.h" #include "data-fd-util.h" #include "fd-util.h" #include "memstream-util.h" @@ -128,8 +129,8 @@ int bus_event_loop_with_idle( if (r == 0 && !exiting && idle) { /* Inform the service manager that we are going down, so that it will queue all - * further start requests, instead of assuming we are already running. */ - sd_notify(false, "STOPPING=1"); + * further start requests, instead of assuming we are still running. */ + (void) sd_notify(false, NOTIFY_STOPPING); r = bus_async_unregister_and_exit(e, bus, name); if (r < 0) diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c index b4a58fc692..a7dcb83206 100644 --- a/src/timedate/timedated.c +++ b/src/timedate/timedated.c @@ -22,6 +22,7 @@ #include "clock-util.h" #include "conf-files.h" #include "constants.h" +#include "daemon-util.h" #include "fd-util.h" #include "fileio-label.h" #include "fileio.h" @@ -1118,21 +1119,15 @@ static int run(int argc, char *argv[]) { umask(0022); - assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGTERM, SIGINT, -1) >= 0); - r = sd_event_default(&event); if (r < 0) return log_error_errno(r, "Failed to allocate event loop: %m"); (void) sd_event_set_watchdog(event, true); - r = sd_event_add_signal(event, NULL, SIGINT, NULL, NULL); + r = sd_event_set_signal_exit(event, true); if (r < 0) - return log_error_errno(r, "Failed to install SIGINT handler: %m"); - - r = sd_event_add_signal(event, NULL, SIGTERM, NULL, NULL); - if (r < 0) - return log_error_errno(r, "Failed to install SIGTERM handler: %m"); + return log_error_errno(r, "Failed to install SIGINT/SIGTERM handlers: %m"); r = connect_bus(&context, event, &bus); if (r < 0) @@ -1148,6 +1143,10 @@ static int run(int argc, char *argv[]) { if (r < 0) return r; + r = sd_notify(false, NOTIFY_READY); + if (r < 0) + log_warning_errno(r, "Failed to send readiness notification, ignoring: %m"); + r = bus_event_loop_with_idle(event, bus, "org.freedesktop.timedate1", DEFAULT_EXIT_USEC, NULL, NULL); if (r < 0) return log_error_errno(r, "Failed to run event loop: %m"); diff --git a/units/systemd-hostnamed.service.in b/units/systemd-hostnamed.service.in index 1cc15dd7cf..ab00c24b53 100644 --- a/units/systemd-hostnamed.service.in +++ b/units/systemd-hostnamed.service.in @@ -15,6 +15,7 @@ Documentation=man:machine-info(5) Documentation=man:org.freedesktop.hostname1(5) [Service] +Type=notify BusName=org.freedesktop.hostname1 CapabilityBoundingSet=CAP_SYS_ADMIN ExecStart={{LIBEXECDIR}}/systemd-hostnamed diff --git a/units/systemd-importd.service.in b/units/systemd-importd.service.in index fc24a05098..daa93776e1 100644 --- a/units/systemd-importd.service.in +++ b/units/systemd-importd.service.in @@ -13,6 +13,7 @@ Documentation=man:systemd-importd.service(8) Documentation=man:org.freedesktop.import1(5) [Service] +Type=notify ExecStart={{LIBEXECDIR}}/systemd-importd BusName=org.freedesktop.import1 KillMode=mixed diff --git a/units/systemd-localed.service.in b/units/systemd-localed.service.in index 19383ae423..4de89aa8dd 100644 --- a/units/systemd-localed.service.in +++ b/units/systemd-localed.service.in @@ -15,6 +15,7 @@ Documentation=man:vconsole.conf(5) Documentation=man:org.freedesktop.locale1(5) [Service] +Type=notify BusName=org.freedesktop.locale1 CapabilityBoundingSet= ExecStart={{LIBEXECDIR}}/systemd-localed diff --git a/units/systemd-timedated.service.in b/units/systemd-timedated.service.in index 00f6643ba7..06c3306a6e 100644 --- a/units/systemd-timedated.service.in +++ b/units/systemd-timedated.service.in @@ -14,6 +14,7 @@ Documentation=man:localtime(5) Documentation=man:org.freedesktop.timedate1(5) [Service] +Type=notify BusName=org.freedesktop.timedate1 CapabilityBoundingSet=CAP_SYS_TIME DeviceAllow=char-rtc r