]> git.ipfire.org Git - pakfire.git/commitdiff
daemon: Cleanup setting up the client
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 26 Jun 2025 09:58:09 +0000 (09:58 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 26 Jun 2025 09:58:09 +0000 (09:58 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/daemon.c

index 1bb26bfc68d88b50246866bd010f8674641725ca..76e3e0a6e5d678e0bb3467cdc04eb079ab709bce 100644 (file)
@@ -48,9 +48,6 @@ struct pakfire_daemon {
        // Builder
        struct pakfire_builder* builder;
 
-       // URL
-       char url[PATH_MAX];
-
        // Event Loop
        sd_event* loop;
 
@@ -272,15 +269,15 @@ static int pakfire_daemon_setup_loop(struct pakfire_daemon* daemon) {
        return 0;
 }
 
-static int pakfire_daemon_configure(struct pakfire_daemon* daemon) {
+static int pakfire_daemon_setup_client(struct pakfire_daemon* self) {
        struct pakfire_config* config = NULL;
        const char* url = NULL;
        int r;
 
        // Fetch the configuration
-       config = pakfire_ctx_get_config(daemon->ctx);
+       config = pakfire_ctx_get_config(self->ctx);
        if (!config) {
-               ERROR(daemon->ctx, "Could not fetch configuration: %m\n");
+               ERROR(self->ctx, "Could not fetch configuration: %m\n");
                r = -errno;
                goto ERROR;
        }
@@ -288,11 +285,14 @@ static int pakfire_daemon_configure(struct pakfire_daemon* daemon) {
        // Fetch the URL
        url = pakfire_config_get(config, "daemon", "url", "https://pakfire.ipfire.org");
 
-       // Store the URL
-       r = pakfire_string_set(daemon->url, url);
+       // Create a new client
+       r = pakfire_client_create(&self->client, self->ctx, url, NULL);
        if (r < 0)
                goto ERROR;
 
+       // Register the ready callback
+       pakfire_client_set_ready_callback(self->client, pakfire_daemon_ready, self);
+
 ERROR:
        if (config)
                pakfire_config_unref(config);
@@ -337,11 +337,6 @@ int pakfire_daemon_create(struct pakfire_daemon** daemon, struct pakfire_ctx* ct
        // Initialize file descriptors
        d->inhibitfd = -EBADF;
 
-       // Read configuration
-       r = pakfire_daemon_configure(d);
-       if (r < 0)
-               goto ERROR;
-
        // Setup the event loop
        r = pakfire_daemon_setup_loop(d);
        if (r)
@@ -352,14 +347,11 @@ int pakfire_daemon_create(struct pakfire_daemon** daemon, struct pakfire_ctx* ct
        if (r < 0)
                goto ERROR;
 
-       // Connect to the build service
-       r = pakfire_client_create(&d->client, d->ctx, d->url, NULL);
+       // Setup client
+       r = pakfire_daemon_setup_client(d);
        if (r < 0)
                goto ERROR;
 
-       // Register the ready callback
-       pakfire_client_set_ready_callback(d->client, pakfire_daemon_ready, d);
-
        // Create builder
        r = pakfire_client_builder(&d->builder, d->client);
        if (r < 0)
@@ -372,7 +364,6 @@ int pakfire_daemon_create(struct pakfire_daemon** daemon, struct pakfire_ctx* ct
 
        // Return the pointer
        *daemon = d;
-
        return 0;
 
 ERROR: