From: Michael Tremer Date: Mon, 30 Jan 2023 19:00:51 +0000 (+0000) Subject: networkd: Move systemd notifications into daemon object X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8a88982f6823b376f2eace8c718dc930072de667;p=network.git networkd: Move systemd notifications into daemon object Signed-off-by: Michael Tremer --- diff --git a/src/networkd/daemon.c b/src/networkd/daemon.c index 9077c545..b93877e4 100644 --- a/src/networkd/daemon.c +++ b/src/networkd/daemon.c @@ -23,6 +23,7 @@ #include #include +#include #include #include "bus.h" @@ -183,14 +184,26 @@ struct nw_daemon* nw_daemon_unref(struct nw_daemon* daemon) { int nw_daemon_run(struct nw_daemon* daemon) { int r; + // We are now ready to process any requests + sd_notify(0, "READY=1\n" "STATUS=Processing requests..."); + // Launch the event loop r = sd_event_loop(daemon->loop); - if (r) { - ERROR("Could not run the event loop: %m\n"); - return r; + if (r < 0) { + ERROR("Could not run the event loop: %s\n", strerror(-r)); + goto ERROR; } + + // Let systemd know that we are shutting down + sd_notify(0, "STOPPING=1\n" "STATUS=Shutting down..."); + return 0; + +ERROR: + sd_notifyf(0, "ERRNO=%i", -r); + + return 1; } int nw_daemon_reload(struct nw_daemon* daemon) { diff --git a/src/networkd/main.c b/src/networkd/main.c index 80123ad7..51a9bbab 100644 --- a/src/networkd/main.c +++ b/src/networkd/main.c @@ -18,10 +18,7 @@ # # #############################################################################*/ -#include -#include - -#include +#include #include "daemon.h" @@ -34,27 +31,14 @@ int main(int argc, char** argv) { // Create the daemon r = nw_daemon_create(&daemon); if (r) - goto ERROR; - - // We are now ready to process any requests - sd_notify(0, "READY=1\n" "STATUS=Processing requests..."); + return r; // Run the daemon r = nw_daemon_run(daemon); - if (r) - goto ERROR; - - // Let systemd know that we are shutting down - sd_notify(0, "STOPPING=1\n" "STATUS=Shutting down..."); - - goto CLEANUP; - -ERROR: - sd_notifyf(0, "ERRNO=%i", errno); -CLEANUP: + // Cleanup if (daemon) nw_daemon_unref(daemon); - return EXIT_FAILURE; + return r; }