sysv execve zipos fix APE if APE loader is installed

This commit is contained in:
Gavin Hayes 2023-02-04 01:59:42 -05:00
parent 385dca4ec0
commit 20b75864e6

View file

@ -85,6 +85,13 @@ int sys_execve(const char *prog, char *const argv[], char *const envp[]) {
newprog = alloca(PATH_MAX); newprog = alloca(PATH_MAX);
fd = _weaken(__zipos_uri_to_mem_file)(&uri, newprog); fd = _weaken(__zipos_uri_to_mem_file)(&uri, newprog);
prog = newprog; prog = newprog;
if ((fd != -1) && IsApeBinary(prog)) {
flags = fcntl(fd, F_GETFD);
if (flags != -1) {
fcntl(fd, F_SETFD, flags & (~FD_CLOEXEC));
flags = fcntl(fd, F_GETFD);
}
}
} else if (IsFreebsd()) { } else if (IsFreebsd()) {
if ((fd = _weaken(__zipos_uri_to_mem_file)(&uri, NULL)) != -1) { if ((fd = _weaken(__zipos_uri_to_mem_file)(&uri, NULL)) != -1) {
return sys_fexecve(fd, argv, envp); return sys_fexecve(fd, argv, envp);
@ -104,13 +111,6 @@ int sys_execve(const char *prog, char *const argv[], char *const envp[]) {
for (i = 0; argv[i];) ++i; for (i = 0; argv[i];) ++i;
buf = alloca(PATH_MAX); buf = alloca(PATH_MAX);
shargs = alloca((i + 4) * sizeof(char *)); shargs = alloca((i + 4) * sizeof(char *));
if (fd != -1) {
flags = fcntl(fd, F_GETFD);
if (flags != -1) {
fcntl(fd, F_SETFD, flags & (~FD_CLOEXEC));
flags = fcntl(fd, F_GETFD);
}
}
if (IsApeBinary(prog) && if (IsApeBinary(prog) &&
(CanExecute((ape = "/usr/bin/ape")) || (CanExecute((ape = "/usr/bin/ape")) ||
CanExecute((ape = Join(firstnonnull(getenv("TMPDIR"), CanExecute((ape = Join(firstnonnull(getenv("TMPDIR"),