]> git.ipfire.org Git - pakfire.git/commitdiff
job: Don't store the configuration as string, parse it straight away
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 22 Jan 2025 10:32:34 +0000 (10:32 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 22 Jan 2025 10:32:34 +0000 (10:32 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/job.c

index 19d790d2c8ed03fffe235776eab1557ca1c0ff2f..ef714cff639497c04897fbf4ffcf66481a97aa15 100644 (file)
@@ -33,6 +33,7 @@
 #include <systemd/sd-event.h>
 
 #include <pakfire/build.h>
+#include <pakfire/config.h>
 #include <pakfire/constants.h>
 #include <pakfire/ctx.h>
 #include <pakfire/daemon.h>
@@ -71,7 +72,7 @@ struct pakfire_job {
        char ccache_path[PATH_MAX];
 
        // Configuration
-       char conf[4096];
+       struct pakfire_config* config;
 
        // PID File Descriptor
        int pidfd;
@@ -190,10 +191,10 @@ static int pakfire_parse_job(struct pakfire_job* job, json_object* data) {
                return -EINVAL;
        }
 
-       // Store the configuration
-       r = pakfire_string_set(job->conf, json_object_get_string(o));
-       if (r) {
-               ERROR(job->ctx, "Could not store the configuration: %m\n");
+       // Parse the configuration
+       r = pakfire_config_parse(job->config, json_object_get_string(o), -1);
+       if (r < 0) {
+               ERROR(job->ctx, "Could not parse the configuration: %s\n", strerror(-r));
 
                return r;
        }
@@ -235,6 +236,8 @@ static void pakfire_job_free(struct pakfire_job* job) {
        if (job->log.stderr)
                pakfire_log_stream_unref(job->log.stderr);
 
+       if (job->config)
+               pakfire_config_unref(job->config);
        if (job->loop)
                sd_event_unref(job->loop);
        if (job->daemon)
@@ -420,7 +423,6 @@ static void pakfire_job_log(void* data, int priority, const char* file,
 
 static int pakfire_job_child(struct pakfire_job* job) {
        struct pakfire_ctx* ctx = NULL;
-       struct pakfire_config* config = NULL;
        struct pakfire_build* build = NULL;
        char job_id[UUID_STR_LEN];
        int build_flags = 0;
@@ -457,24 +459,12 @@ static int pakfire_job_child(struct pakfire_job* job) {
        // Setup logging
        pakfire_ctx_set_log_callback(ctx, pakfire_job_log, job);
 
-       // Create a new configuration object
-       r = pakfire_config_create(&config);
-       if (r < 0)
-               goto ERROR;
-
-       // Parse the configuration
-       r = pakfire_config_parse(config, job->conf, -1);
-       if (r < 0) {
-               ERROR(ctx, "Could not parse configuration: %s\n", strerror(-r));
-               goto ERROR;
-       }
-
        // Disable the ccache
        if (!(job->flags & PAKFIRE_JOB_CCACHE))
                build_flags |= PAKFIRE_BUILD_DISABLE_CCACHE;
 
        // Create a new build environment
-       r = pakfire_build_create(&build, ctx, config, job->arch, job_id, build_flags);
+       r = pakfire_build_create(&build, ctx, job->config, job->arch, job_id, build_flags);
        if (r) {
                ERROR(ctx, "Could not setup the build environment: %m\n");
                r = -errno;
@@ -502,8 +492,6 @@ static int pakfire_job_child(struct pakfire_job* job) {
 ERROR:
        if (build)
                pakfire_build_unref(build);
-       if (config)
-               pakfire_config_unref(config);
        if (ctx)
                pakfire_ctx_unref(ctx);
 
@@ -738,6 +726,11 @@ int pakfire_job_create(struct pakfire_job** job, struct pakfire_ctx* ctx,
        // Initialize the PID file descriptor
        j->pidfd = -1;
 
+       // Initialize the configuration
+       r = pakfire_config_create(&j->config);
+       if (r < 0)
+               goto ERROR;
+
        // Allocate the log buffer
        r = pakfire_log_buffer_create(&j->log.buffer, j->ctx, 1024);
        if (r < 0)