]> git.ipfire.org Git - pakfire.git/commitdiff
job: Create an own independant context for the child process
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 5 Oct 2024 10:55:48 +0000 (10:55 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 5 Oct 2024 10:55:48 +0000 (10:55 +0000)
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 <michael.tremer@ipfire.org>
src/libpakfire/job.c

index 9e5e0a929fb469e5ba022c67f8f7de0f247af4d7..fdaddfc347617d22b1b76387fb9ddcffe7765096 100644 (file)
@@ -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);