diff options
author | Tom Gundersen <teg@jklm.no> | 2016-11-28 20:42:40 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2016-11-28 20:42:40 +0100 |
commit | b76d99d9e66f965b79dade55ab719d54a17e709c (patch) | |
tree | e0d45453cbd3ad9c958de54d040d614ea5e88f35 /src/network/networkd.c | |
parent | dc3b8afb93f188f212218487ab62fd3f12a2b58f (diff) |
networkd: move event loop handling out of the manager (#4723)
This will allow us to have several managers sharing an event loop
and running in parallel, as if they were running in separate processes.
The long term-aim is to allow networkd to be split into separate
processes, so restructure the code to make this simpler.
For now we drop the exit-on-idle logic, as this was anyway severely
restricted at the moment. Once split, we will revisit this as it may
then make more sense again.
Diffstat (limited to 'src/network/networkd.c')
-rw-r--r-- | src/network/networkd.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/network/networkd.c b/src/network/networkd.c index 2851432eff..fe60f1ed14 100644 --- a/src/network/networkd.c +++ b/src/network/networkd.c @@ -18,6 +18,7 @@ ***/ #include "sd-daemon.h" +#include "sd-event.h" #include "capability-util.h" #include "networkd-conf.h" @@ -26,6 +27,7 @@ #include "user-util.h" int main(int argc, char *argv[]) { + sd_event *event = NULL; _cleanup_manager_free_ Manager *m = NULL; const char *user = "systemd-network"; uid_t uid; @@ -78,7 +80,15 @@ int main(int argc, char *argv[]) { assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGTERM, SIGINT, -1) >= 0); - r = manager_new(&m); + r = sd_event_default(&event); + if (r < 0) + goto out; + + sd_event_set_watchdog(event, true); + sd_event_add_signal(event, NULL, SIGTERM, NULL, NULL); + sd_event_add_signal(event, NULL, SIGINT, NULL, NULL); + + r = manager_new(&m, event); if (r < 0) { log_error_errno(r, "Could not create manager: %m"); goto out; @@ -118,22 +128,29 @@ int main(int argc, char *argv[]) { goto out; } + r = manager_start(m); + if (r < 0) { + log_error_errno(r, "Could not start manager: %m"); + goto out; + } + log_info("Enumeration completed"); sd_notify(false, "READY=1\n" "STATUS=Processing requests..."); - r = manager_run(m); + r = sd_event_loop(event); if (r < 0) { log_error_errno(r, "Event loop failed: %m"); goto out; } - out: sd_notify(false, "STOPPING=1\n" "STATUS=Shutting down..."); + sd_event_unref(event); + return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; } |