diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-03-09 19:51:58 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-03-10 15:41:07 -0500 |
| commit | 3169f0529b22fca2a387a841a62fec29b3d2096a (patch) | |
| tree | 11680a5f5e95f6b5cd32436f37ebb5ec68541bfc /src/Module.zig | |
| parent | 904f414e7eab7bc0f7ea00f616831bfc3c1f18a4 (diff) | |
| download | zig-3169f0529b22fca2a387a841a62fec29b3d2096a.tar.gz zig-3169f0529b22fca2a387a841a62fec29b3d2096a.zip | |
eliminate posix_spawn from the standard library
Today I found out that posix_spawn is trash. It's actually implemented
on top of fork/exec inside of libc (or libSystem in the case of macOS).
So, anything posix_spawn can do, we can do better. In particular, what
we can do better is handle spawning of child processes that are
potentially foreign binaries. If you try to spawn a wasm binary, for
example, posix spawn does the following:
* Goes ahead and creates a child process.
* The child process writes "foo.wasm: foo.wasm: cannot execute binary file"
to stderr (yes, it prints the filename twice).
* The child process then exits with code 126.
This behavior is indistinguishable from the binary being successfully
spawned, and then printing to stderr, and exiting with a failure -
something that is an extremely common occurrence.
Meanwhile, using the lower level fork/exec will simply return ENOEXEC
code from the execve syscall (which is mapped to zig error.InvalidExe).
The posix_spawn behavior means the zig build runner can't tell the
difference between a failure to run a foreign binary, and a binary that
did run, but failed in some other fashion. This is unacceptable, because
attempting to excecve is the proper way to support things like Rosetta.
Diffstat (limited to 'src/Module.zig')
0 files changed, 0 insertions, 0 deletions
