Skip to main content

zexecve

Function zexecve 

Source
pub fn zexecve(pth: &str, argv: &[String], newenvp: Option<&[String]>) -> i32
Expand description

Port of static int zexecve(char *pth, char **argv, char **newenvp) from Src/exec.c:504. Wraps execve(2) with:

  • $_ env var stamped to absolute pth (c:514-520)
  • winch signal unblock right before the syscall (c:527)
  • on ENOEXEC / ENOENT: reads the first POUNDBANGLIMIT bytes, parses a #!interp arg shebang and re-execs the interpreter (c:534-628). For ENOEXEC with no shebang, binary-safety check then falls back to /bin/sh script per POSIX (c:588-628).

Returns errno from the failing exec — execve only returns on failure, so success means the calling process is already replaced.

§=================== WARNING — DIVERGENCE ==================== (a) C uses static char buf[PATH_MAX*2+1] for the _=... env string; Rust uses a stack String (consumed by zputenv). (b) closedumps() for !FD_CLOEXEC (c:521-523) called unconditionally as a no-op when FD_CLOEXEC is platform default. (c) unmetafy(pth, NULL) / round-trip metafy at c:510-513, c:639-642 — handled implicitly via &str ↔ CString. (d) metafy(execvebuf+2, -1, META_STATIC) (c:551, 575) — we drop the metafy and pass byte ranges to zerr directly. (e) argv[-1] / argv[-2] shebang interpreter slot-overwriting (C overwrites BEFORE argv[0]) — Rust rebuilds a fresh Vec<String> with interp + optional arg + original argv tail since Vec doesn’t expose negative indexing. (f) environ is FFI-loaded only when newenvp is None.