#include <errno.h>
#include <stdlib.h>
+#include <sys/mman.h>
#include <sys/mount.h>
#include <time.h>
#include <unistd.h>
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)
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
if (r)
ERROR(build->ctx, "Script '%s' failed with status %d\n", filename, r);
+ERROR:
if (script)
- free(script);
+ munmap(script, length);
return r;
}