zipos execve: move implementation out of execve-sysv into execve.c

This commit is contained in:
Gavin Hayes 2023-02-24 11:19:01 -05:00
parent 2c9e197843
commit ae26246a77
2 changed files with 20 additions and 23 deletions

View file

@ -25,7 +25,6 @@
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/intrin/bits.h" #include "libc/intrin/bits.h"
#include "libc/intrin/safemacros.internal.h" #include "libc/intrin/safemacros.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/mem/alloca.h" #include "libc/mem/alloca.h"
#include "libc/paths.h" #include "libc/paths.h"
#include "libc/runtime/runtime.h" #include "libc/runtime/runtime.h"
@ -34,7 +33,6 @@
#include "libc/sysv/consts/o.h" #include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/ok.h" #include "libc/sysv/consts/ok.h"
#include "libc/sysv/errfuns.h" #include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
static bool CanExecute(const char *path) { static bool CanExecute(const char *path) {
return !sys_faccessat(AT_FDCWD, path, X_OK, 0); return !sys_faccessat(AT_FDCWD, path, X_OK, 0);
@ -77,19 +75,6 @@ int sys_execve(const char *prog, char *const argv[], char *const envp[]) {
char *buf; char *buf;
char **shargs; char **shargs;
const char *ape; const char *ape;
struct ZiposUri uri;
if (_weaken(__zipos_parseuri) &&
(_weaken(__zipos_parseuri)(prog, &uri) != -1)) {
rc = _weaken(__zipos_open)(&uri, O_RDONLY | O_CLOEXEC, 0);
if (rc != -1) {
const int zipFD = rc;
strace_enabled(-1);
rc = fexecve(zipFD, argv, envp);
close(zipFD);
strace_enabled(+1);
}
return rc;
}
e = errno; e = errno;
__sys_execve(prog, argv, envp); __sys_execve(prog, argv, envp);
if (errno == ENOEXEC) { if (errno == ENOEXEC) {

View file

@ -32,6 +32,7 @@
#include "libc/log/libfatal.internal.h" #include "libc/log/libfatal.internal.h"
#include "libc/sysv/consts/o.h" #include "libc/sysv/consts/o.h"
#include "libc/sysv/errfuns.h" #include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
/** /**
* Replaces current process with program. * Replaces current process with program.
@ -51,6 +52,7 @@
* @vforksafe * @vforksafe
*/ */
int execve(const char *prog, char *const argv[], char *const envp[]) { int execve(const char *prog, char *const argv[], char *const envp[]) {
struct ZiposUri uri;
int rc; int rc;
size_t i; size_t i;
if (!prog || !argv || !envp || if (!prog || !argv || !envp ||
@ -61,16 +63,26 @@ int execve(const char *prog, char *const argv[], char *const envp[]) {
} else { } else {
STRACE("execve(%#s, %s, %s) → ...", prog, DescribeStringList(argv), STRACE("execve(%#s, %s, %s) → ...", prog, DescribeStringList(argv),
DescribeStringList(envp)); DescribeStringList(envp));
if (!IsWindows()) { rc = 0;
rc = 0; if (IsLinux() && __execpromises && _weaken(sys_pledge_linux)) {
if (IsLinux() && __execpromises && _weaken(sys_pledge_linux)) { rc = _weaken(sys_pledge_linux)(__execpromises, __pledge_mode);
rc = _weaken(sys_pledge_linux)(__execpromises, __pledge_mode); }
} if (!rc) {
if (!rc) { if (_weaken(__zipos_parseuri) &&
(_weaken(__zipos_parseuri)(prog, &uri) != -1)) {
rc = _weaken(__zipos_open)(&uri, O_RDONLY | O_CLOEXEC, 0);
if (rc != -1) {
const int zipFD = rc;
strace_enabled(-1);
rc = fexecve(zipFD, argv, envp);
close(zipFD);
strace_enabled(+1);
}
} else if (!IsWindows()) {
rc = sys_execve(prog, argv, envp); rc = sys_execve(prog, argv, envp);
} else {
rc = sys_execve_nt(prog, argv, envp);
} }
} else {
rc = sys_execve_nt(prog, argv, envp);
} }
} }
STRACE("execve(%#s) failed %d% m", prog, rc); STRACE("execve(%#s) failed %d% m", prog, rc);