]> git.ipfire.org Git - pakfire.git/commitdiff
build: Use factory function to create jail
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 3 Aug 2022 08:44:05 +0000 (08:44 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 3 Aug 2022 08:44:05 +0000 (08:44 +0000)
This jail can be configured and customised for the build process.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c

index 6762f8d937efc3b85b24e38bc4cb6c24cc05f3e9..c4094f49c4237fb70970764ed2f214784afa36aa 100644 (file)
@@ -29,6 +29,7 @@
 #include <pakfire/execute.h>
 #include <pakfire/dist.h>
 #include <pakfire/file.h>
+#include <pakfire/jail.h>
 #include <pakfire/logging.h>
 #include <pakfire/mount.h>
 #include <pakfire/package.h>
@@ -58,8 +59,32 @@ static const char* stages[] = {
        "\n" \
        "exit 0\n"
 
+/*
+       This function creates a new jail which is pre-configured for a build job.
+
+       TODO Add resource limits
+*/
+static struct pakfire_jail* pakfire_build_make_jail(struct pakfire* pakfire) {
+       struct pakfire_jail* jail = NULL;
+       int r;
+
+       // Create a new jail
+       r = pakfire_jail_create(&jail, pakfire, 0);
+       if (r)
+               goto ERROR;
+
+       return jail;
+
+ERROR:
+       if (jail)
+               pakfire_jail_unref(jail);
+
+       return NULL;
+}
+
 static int pakfire_build_run_script(struct pakfire* pakfire, const char* filename, const char* args[],
                pakfire_execute_logging_callback logging_callback, void* data) {
+       struct pakfire_jail* jail = NULL;
        char* script = NULL;
        size_t size = 0;
        char path[PATH_MAX];
@@ -83,13 +108,27 @@ static int pakfire_build_run_script(struct pakfire* pakfire, const char* filenam
                goto ERROR;
        }
 
-       // Execute it
-       r = pakfire_execute_script(pakfire, script, size, args, NULL, 0, logging_callback, data);
+       // Create a new jail
+       jail = pakfire_build_make_jail(pakfire);
+       if (!jail)
+               goto ERROR;
+
+       // Configure logging
+       if (logging_callback) {
+               r = pakfire_jail_set_log_callback(jail, logging_callback, data);
+               if (r)
+                       goto ERROR;
+       }
+
+       // Execute the script
+       r = pakfire_jail_exec_script(jail, script, size, args);
        if (r) {
                ERROR(pakfire, "Script '%s' failed with status %d\n", filename, r);
        }
 
 ERROR:
+       if (jail)
+               pakfire_jail_unref(jail);
        if (script)
                free(script);