From: Michael Tremer Date: Sat, 11 Jan 2025 18:57:15 +0000 (+0000) Subject: build: Map scripts instead of reading them X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b54d85e1e6bd5a2baa594aec619d1502d327674e;p=people%2Fric9%2Fpakfire.git build: Map scripts instead of reading them Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/build.c b/src/pakfire/build.c index f037a4662..12887f779 100644 --- a/src/pakfire/build.c +++ b/src/pakfire/build.c @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -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; }