Clean up executable after running it
This commit is contained in:
parent
c951ee5915
commit
c9cb7ccb40
16
tomo.c
16
tomo.c
@ -5,6 +5,7 @@
|
|||||||
#include <gc/cord.h>
|
#include <gc/cord.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <printf.h>
|
#include <printf.h>
|
||||||
|
#include <spawn.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -198,8 +199,19 @@ int main(int argc, char *argv[])
|
|||||||
for (int64_t i = 0; i < args.length; i++)
|
for (int64_t i = 0; i < args.length; i++)
|
||||||
prog_args[i + 1] = Text$as_c_string(*(Text_t*)(args.data + i*args.stride));
|
prog_args[i + 1] = Text$as_c_string(*(Text_t*)(args.data + i*args.stride));
|
||||||
prog_args[1 + args.length] = NULL;
|
prog_args[1 + args.length] = NULL;
|
||||||
execv(prog_args[0], prog_args);
|
pid_t child;
|
||||||
errx(1, "Failed to run compiled program");
|
if (posix_spawn(&child, prog_args[0], NULL, NULL, prog_args, NULL) != 0)
|
||||||
|
err(1, "Failed to run compiled program: %s", prog_args[0]);
|
||||||
|
assert(child);
|
||||||
|
int status;
|
||||||
|
while (waitpid(child, &status, 0) < 0 && errno == EINTR) {
|
||||||
|
if (WIFEXITED(status) || WIFSIGNALED(status))
|
||||||
|
break;
|
||||||
|
else if (WIFSTOPPED(status))
|
||||||
|
kill(child, SIGCONT);
|
||||||
|
}
|
||||||
|
unlink(prog_args[0]);
|
||||||
|
return WIFEXITED(status) ? WEXITSTATUS(status) : EXIT_FAILURE;
|
||||||
} else {
|
} else {
|
||||||
env_t *env = global_env();
|
env_t *env = global_env();
|
||||||
Array_t object_files = {},
|
Array_t object_files = {},
|
||||||
|
Loading…
Reference in New Issue
Block a user