]> git.ipfire.org Git - pakfire.git/commitdiff
daemon: Connect to the system dbus
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 27 Jan 2025 10:37:23 +0000 (10:37 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 27 Jan 2025 10:37:23 +0000 (10:37 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/daemon.c

index 2ba904d4866c4ebd4babf14ae5fc376ab65986af..30106b1a0f946f27751ae8643510027603c3e4a8 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <krb5/krb5.h>
 
+#include <systemd/sd-bus.h>
 #include <systemd/sd-daemon.h>
 #include <systemd/sd-event.h>
 
@@ -67,6 +68,9 @@ struct pakfire_daemon {
        // Event Loop
        sd_event* loop;
 
+       // dbus
+       sd_bus* bus;
+
        // Kerberos Authentication
        struct {
                // Context
@@ -817,6 +821,19 @@ ERROR:
        return r;
 }
 
+static int pakfire_daemon_setup_bus(struct pakfire_daemon* daemon) {
+       int r;
+
+       // Connect to the system bus
+       r = sd_bus_open_system(&daemon->bus);
+       if (r < 0) {
+               ERROR(daemon->ctx, "Could not connect to system bus: %s\n", strerror(-r));
+               return r;
+       }
+
+       return 0;
+}
+
 static int pakfire_daemon_setup_loop(struct pakfire_daemon* daemon) {
        int r;
 
@@ -950,6 +967,8 @@ static void pakfire_daemon_free(struct pakfire_daemon* daemon) {
                pakfire_xfer_unref(daemon->control);
        if (daemon->loop)
                sd_event_unref(daemon->loop);
+       if (daemon->bus)
+               sd_bus_unref(daemon->bus);
        if (daemon->ctx)
                pakfire_ctx_unref(daemon->ctx);
        free(daemon);
@@ -980,6 +999,11 @@ int pakfire_daemon_create(struct pakfire_daemon** daemon, struct pakfire_ctx* ct
        if (r)
                goto ERROR;
 
+       // Setup dbus
+       r = pakfire_daemon_setup_bus(d);
+       if (r < 0)
+               goto ERROR;
+
        // Setup Kerberos Authentication
        r = pakfire_daemon_setup_krb5(d);
        if (r)