From 20b75864e61ddadba4d6a2a6fa77200fc6eca090 Mon Sep 17 00:00:00 2001 From: Gavin Hayes Date: Sat, 4 Feb 2023 01:59:42 -0500 Subject: [PATCH] sysv execve zipos fix APE if APE loader is installed --- libc/calls/execve-sysv.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libc/calls/execve-sysv.c b/libc/calls/execve-sysv.c index 7bd2987be..01b44e11f 100644 --- a/libc/calls/execve-sysv.c +++ b/libc/calls/execve-sysv.c @@ -85,6 +85,13 @@ int sys_execve(const char *prog, char *const argv[], char *const envp[]) { newprog = alloca(PATH_MAX); fd = _weaken(__zipos_uri_to_mem_file)(&uri, 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()) { if ((fd = _weaken(__zipos_uri_to_mem_file)(&uri, NULL)) != -1) { 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; buf = alloca(PATH_MAX); 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) && (CanExecute((ape = "/usr/bin/ape")) || CanExecute((ape = Join(firstnonnull(getenv("TMPDIR"),