]> git.ipfire.org Git - pakfire.git/commitdiff
daemon: Create the control connection as soon as the client is ready
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 Jun 2025 13:42:52 +0000 (13:42 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 Jun 2025 13:42:52 +0000 (13:42 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/daemon.c

index d550ba806df5d31eb853e58bea55985a68d5a79f..178c19328497b785bf0f8bac34d0afabbdf04a36 100644 (file)
@@ -748,8 +748,7 @@ static int pakfire_daemon_connected(struct pakfire_xfer* xfer, void* data) {
        return 0;
 }
 
-static int pakfire_daemon_connect(sd_event_source* s, uint64_t usec, void* data) {
-       struct pakfire_daemon* daemon = data;
+static int pakfire_daemon_connect(struct pakfire_daemon* daemon) {
        struct pakfire_sysinfo sysinfo = {};
        struct pakfire_cpuinfo cpuinfo = {};
        struct pakfire_xfer* xfer = NULL;
@@ -874,6 +873,16 @@ ERROR:
        return r;
 }
 
+/*
+       Called when the client is ready and we can start making connections...
+*/
+static int pakfire_daemon_ready(struct pakfire_client* client, void* data) {
+       struct pakfire_daemon* self = data;
+
+       // Connect the control connection
+       return pakfire_daemon_connect(self);
+}
+
 // Currently we are not doing anything here. We just need to block SIGCHLD.
 static int pakfire_daemon_SIGCHLD(sd_event_source* s, const struct signalfd_siginfo* si, void* data) {
        return 0;
@@ -988,13 +997,15 @@ static int pakfire_daemon_setup_loop(struct pakfire_daemon* daemon) {
                return r;
        }
 
+#if 0
        // Setup the reconnection timer
        r = sd_event_add_time_relative(daemon->loop, &daemon->connect_timer,
-               CLOCK_MONOTONIC, 0, 0, pakfire_daemon_connect, daemon);
+               CLOCK_MONOTONIC, 0, 0, pakfire_daemon_reconnect, daemon);
        if (r < 0) {
                ERROR(daemon->ctx, "Could not register the connection timer: %s\n", strerror(-r));
                return r;
        }
+#endif
 
        // Disable the reconnection timer until we are authenticated
        r = sd_event_source_set_enabled(daemon->connect_timer, SD_EVENT_OFF);
@@ -1112,6 +1123,9 @@ int pakfire_daemon_create(struct pakfire_daemon** daemon, struct pakfire_ctx* ct
        if (r < 0)
                goto ERROR;
 
+       // Register the ready callback
+       pakfire_client_set_ready_callback(d->client, pakfire_daemon_ready, d);
+
        // Create the cgroup
        r = pakfire_cgroup_create(&d->cgroup, d->ctx, NULL, "pakfire-daemon", 0);
        if (r < 0)