diff options
| author | 2025-12-08 09:17:17 +0100 | |
|---|---|---|
| committer | 2025-12-08 09:17:17 +0100 | |
| commit | 046e4271ba9cd7baf4f8fb4c444da8dd378375ad (patch) | |
| tree | 61d4ba2cdb2d4093e27d6b87c2220229b7840bca /main.c | |
| parent | 6a335e2b7d47afdb5e37034a095aaa26a34d7ee1 (diff) | |
driver: use fexecve for -run
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 35 |
1 files changed, 18 insertions, 17 deletions
@@ -268,10 +268,10 @@ static void cleantemps(void) { for (int i = 0; i < task.ninf; ++i) { - if (tempobj[i]) unlink(tempobj[i]); + if (tempobj[i]) unlink(tempobj[i]), tempobj[i] = NULL; } if (tempout) - unlink(tempout); + unlink(tempout), tempout = NULL; } static void sigcleantemps(int _) @@ -362,6 +362,8 @@ dolink(void) return WEXITSTATUS(wstat); } +#include <fcntl.h> /* open */ + static int dorun(void) { @@ -371,24 +373,23 @@ dorun(void) efmt(" %s", *s); efmt("\n"); } - pid_t p; - if ((p = fork()) < 0) { - error(NULL, "fork(): %s\n", strerror(errno)); - exit(1); - } else if (p == 0) { - if (!execv(task.out, task.runargs - 1)) { - error(NULL, "execv(): %s\n", strerror(errno)); - exit(1); - } + int fd = open(task.out, O_RDONLY); + if (fd < 0) { + error(NULL, "open(): %s\n", strerror(errno)); + return 1; } - int wstat; - waitpid(p, &wstat, 0); - if (!WIFEXITED(wstat)) return 127; - return WEXITSTATUS(wstat); + if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) { + error(NULL, "fcntl(): %s\n", strerror(errno)); + return 1; + } + cleantemps(); + extern char **environ; + int fexecve(int fd, char *const argv[], char *const envp[]); + fexecve(fd, task.runargs - 1, environ); + error(NULL, "fexecv(): %s\n", strerror(errno)); + return 1; } -#include <fcntl.h> /* open */ - static int driver(void) { |