From: Michael Tremer Date: Thu, 26 Jun 2025 09:58:09 +0000 (+0000) Subject: daemon: Cleanup setting up the client X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=efd53f5fbcccb9a54c2ea8fb503f39af76ff3dc4;p=pakfire.git daemon: Cleanup setting up the client Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/daemon.c b/src/pakfire/daemon.c index 1bb26bfc..76e3e0a6 100644 --- a/src/pakfire/daemon.c +++ b/src/pakfire/daemon.c @@ -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: