]> git.ipfire.org Git - network.git/commitdiff
networkd: Move systemd notifications into daemon object
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 30 Jan 2023 19:00:51 +0000 (19:00 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 30 Jan 2023 19:00:51 +0000 (19:00 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/networkd/daemon.c
src/networkd/main.c

index 9077c545e5079a77c2ad408cb0d8f25aecd78ab3..b93877e45093bb1ac14c63310193baddd43ef518 100644 (file)
@@ -23,6 +23,7 @@
 #include <string.h>
 
 #include <systemd/sd-bus.h>
+#include <systemd/sd-daemon.h>
 #include <systemd/sd-event.h>
 
 #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) {
index 80123ad704ed2b0e32e6ed9c337faecf95e2ba53..51a9bbab730147b8215ab3703d0da98edfe59387 100644 (file)
 #                                                                             #
 #############################################################################*/
 
-#include <errno.h>
-#include <stdlib.h>
-
-#include <systemd/sd-daemon.h>
+#include <stddef.h>
 
 #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;
 }