]> git.ipfire.org Git - people/ric9/pakfire.git/commitdiff
build: Map scripts instead of reading them
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 11 Jan 2025 18:57:15 +0000 (18:57 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 11 Jan 2025 18:57:15 +0000 (18:57 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/build.c

index f037a466235275bb354def165ac0930c07b0b7d1..12887f7795a8c56eeb0d9283ea8b23d00cb1450d 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <errno.h>
 #include <stdlib.h>
+#include <sys/mman.h>
 #include <sys/mount.h>
 #include <time.h>
 #include <unistd.h>
@@ -250,12 +251,10 @@ static int pakfire_build_read_script(struct pakfire_build* build,
                goto ERROR;
        }
 
-       // Read the file into a the buffer
-       r = pakfire_read_file_into_buffer(f, buffer, length);
-       if (r) {
-               ERROR(build->ctx, "Could not read script: %m\n");
+       // Map the script into the buffer
+       r = pakfire_mmap(fileno(f), buffer, length);
+       if (r < 0)
                goto ERROR;
-       }
 
 ERROR:
        if (f)
@@ -270,18 +269,17 @@ static int pakfire_build_run_script(
                const char* args[],
                pakfire_pty_stdin_callback stdin_callback, void* stdin_data,
                pakfire_pty_stdout_callback stdout_callback, void* stdout_data) {
-       int r;
-
        char* script = NULL;
        size_t length = 0;
+       int r;
 
        DEBUG(build->ctx, "Running build script '%s'...\n", filename);
 
        // Read the script
        r = pakfire_build_read_script(build, filename, &script, &length);
-       if (r) {
-               ERROR(build->ctx, "Could not read script %s: %m\n", filename);
-               return r;
+       if (r < 0) {
+               ERROR(build->ctx, "Could not read script %s: %s\n", filename, strerror(-r));
+               goto ERROR;
        }
 
        // Execute the script
@@ -290,8 +288,9 @@ static int pakfire_build_run_script(
        if (r)
                ERROR(build->ctx, "Script '%s' failed with status %d\n", filename, r);
 
+ERROR:
        if (script)
-               free(script);
+               munmap(script, length);
 
        return r;
 }