From: Michael Tremer Date: Sat, 5 Oct 2024 10:55:48 +0000 (+0000) Subject: job: Create an own independant context for the child process X-Git-Tag: 0.9.30~1164 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cf640328a04b51faf77eedf57fe1ccaab7a9568c;p=pakfire.git job: Create an own independant context for the child process This prevents us to inherit anything from the parent process and allows us to run a totally different configuration in the child. Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/job.c b/src/libpakfire/job.c index 9e5e0a929..fdaddfc34 100644 --- a/src/libpakfire/job.c +++ b/src/libpakfire/job.c @@ -276,6 +276,7 @@ static int pakfire_job_parent(struct pakfire_job* job) { } static int pakfire_job_child(struct pakfire_job* job) { + struct pakfire_ctx* ctx = NULL; struct pakfire* pakfire = NULL; struct pakfire_build* build = NULL; char job_id[UUID_STR_LEN]; @@ -290,18 +291,25 @@ static int pakfire_job_child(struct pakfire_job* job) { // Format the job ID as string uuid_unparse(job->job_id, job_id); + // Create a new context + r = pakfire_ctx_create(&ctx, NULL); + if (r < 0) { + CTX_ERROR(job->ctx, "Could not create a new context: %s\n", strerror(-r)); + goto ERROR; + } + // Map the configuration conf = fmemopen(job->conf, strlen(job->conf), "r"); if (!conf) { - CTX_ERROR(job->ctx, "Could not map the configuration into memory: %m\n"); + CTX_ERROR(ctx, "Could not map the configuration into memory: %m\n"); r = -errno; goto ERROR; } // Create a new Pakfire instance - r = pakfire_create(&pakfire, job->ctx, NULL, job->arch, conf, PAKFIRE_FLAGS_BUILD); + r = pakfire_create(&pakfire, ctx, NULL, job->arch, conf, PAKFIRE_FLAGS_BUILD); if (r) { - CTX_ERROR(job->ctx, "Could not initialize Pakfire: %m\n"); + CTX_ERROR(ctx, "Could not initialize Pakfire: %m\n"); r = -errno; goto ERROR; } @@ -313,7 +321,7 @@ static int pakfire_job_child(struct pakfire_job* job) { // Create a new build environment r = pakfire_build_create(&build, pakfire, job_id, build_flags); if (r) { - CTX_ERROR(job->ctx, "Could not setup the build environment: %m\n"); + CTX_ERROR(ctx, "Could not setup the build environment: %m\n"); r = -errno; goto ERROR; } @@ -324,7 +332,7 @@ static int pakfire_job_child(struct pakfire_job* job) { // XXX THIS NEEDS TO BE PREFIXED WITH THE BASE PATH r = pakfire_build_set_ccache_path(build, job->ccache_path); if (r) { - CTX_ERROR(job->ctx, "Could not set ccache path: %m\n"); + CTX_ERROR(ctx, "Could not set ccache path: %m\n"); r = -errno; goto ERROR; } @@ -341,6 +349,8 @@ ERROR: pakfire_build_unref(build); if (pakfire) pakfire_unref(pakfire); + if (ctx) + pakfire_ctx_unref(ctx); if (conf) fclose(conf);