#include <string.h>
#include <systemd/sd-bus.h>
+#include <systemd/sd-daemon.h>
#include <systemd/sd-event.h>
#include "bus.h"
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) {
# #
#############################################################################*/
-#include <errno.h>
-#include <stdlib.h>
-
-#include <systemd/sd-daemon.h>
+#include <stddef.h>
#include "daemon.h"
// 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;
}