]> git.ipfire.org Git - pakfire.git/commitdiff
job: Initialize Pakfire in the child process
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 4 Oct 2024 18:09:06 +0000 (18:09 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 4 Oct 2024 18:09:06 +0000 (18:09 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/job.c

index 7fdac057b356236b42088b2d7133e8a86317fc48..171a87b57c33286d1e7806cb269e0d6333b6bd51 100644 (file)
@@ -275,13 +275,44 @@ static int pakfire_job_parent(struct pakfire_job* job) {
 }
 
 static int pakfire_job_child(struct pakfire_job* job) {
+       struct pakfire* pakfire = NULL;
+       FILE* conf = NULL;
+       int r;
+
        // Fetch our PID
        pid_t pid = getpid();
 
        CTX_DEBUG(job->ctx, "Launched job child as PID %d\n", pid);
 
+       // 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");
+               r = -errno;
+               goto ERROR;
+       }
+
+       // Create a new Pakfire instance
+       r = pakfire_create(&pakfire, job->ctx, NULL, job->arch, conf, PAKFIRE_FLAGS_BUILD);
+       if (r) {
+               CTX_ERROR(job->ctx, "Could not initialize Pakfire: %m\n");
+               r = -errno;
+               goto ERROR;
+       }
+
        // XXX TODO
-       return 1;
+       for (unsigned int i = 0; i < 5; i++) {
+               printf("WORK\n");
+               sleep(1);
+       }
+
+ERROR:
+       if (pakfire)
+               pakfire_unref(pakfire);
+       if (conf)
+               fclose(conf);
+
+       return r;
 }
 
 /*