From: Michael Tremer Date: Wed, 22 Jan 2025 10:32:34 +0000 (+0000) Subject: job: Don't store the configuration as string, parse it straight away X-Git-Tag: 0.9.30~399 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4d12b705ff07263a81cb08032581774e9c80ff75;p=pakfire.git job: Don't store the configuration as string, parse it straight away Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/job.c b/src/pakfire/job.c index 19d790d2..ef714cff 100644 --- a/src/pakfire/job.c +++ b/src/pakfire/job.c @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -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)