]> git.ipfire.org Git - pakfire.git/commitdiff
client: Move the authentication timer from the daemon
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 24 Jun 2025 15:56:19 +0000 (15:56 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 24 Jun 2025 15:56:19 +0000 (15:56 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/client.c

index 7450957f885dcf1502cf4e70735aadf841d1046c..289ef8780f145f2a40412ea7871b84fa35f1f027 100644 (file)
@@ -55,6 +55,12 @@ struct pakfire_client {
        // Configuration
        char keytab[PATH_MAX];
 
+       // Authentication
+       struct pakfire_client_auth {
+               // Timer
+               sd_event_source* timer;
+       } auth;
+
        // Tokens
        char access_token[1024];
        time_t access_token_expires_at;
@@ -230,6 +236,14 @@ ERROR:
        return r;
 }
 
+static int pakfire_client_auth_timer(sd_event_source* event, uint64_t usec, void* data) {
+       struct pakfire_client* self = data;
+
+       DEBUG(self->ctx, "Authentication timer fired\n");
+
+       return 0;
+}
+
 static int pakfire_client_xfer_auth(struct pakfire_client* self, struct pakfire_xfer* xfer) {
        int r;
 
@@ -256,6 +270,9 @@ static int pakfire_client_xfer_auth(struct pakfire_client* self, struct pakfire_
 }
 
 static void pakfire_client_free(struct pakfire_client* self) {
+       if (self->auth.timer)
+               sd_event_source_unref(self->auth.timer);
+
        // Event Loop
        if (self->loop)
                sd_event_unref(self->loop);
@@ -297,6 +314,21 @@ int pakfire_client_create(struct pakfire_client** client,
        if (r < 0)
                goto ERROR;
 
+       // Setup the authentication timer
+       r = sd_event_add_time_relative(self->loop, &self->auth.timer,
+                       CLOCK_MONOTONIC, 0, 0, pakfire_client_auth_timer, self);
+       if (r < 0) {
+               ERROR(self->ctx, "Could not register the auth timer: %s\n", strerror(-r));
+               goto ERROR;
+       }
+
+       // Disable the authentication timer
+       r = sd_event_source_set_enabled(self->auth.timer, SD_EVENT_OFF);
+       if (r < 0) {
+               ERROR(self->ctx, "Could not activate the auth timer: %s\n", strerror(-r));
+               goto ERROR;
+       }
+
        DEBUG(self->ctx, "Pakfire Build Service initialized for %s\n",
                pakfire_client_get_url(self));