commit 05630274f1df46cbf0cc273364f51a44e41708e0
parent 0c1949c227786cb3b75ab13ffde13935798b841a
Author: triesap <tyson@radroots.org>
Date: Thu, 9 Apr 2026 18:43:21 +0000
tests: replace hyf process vfork harness
- switch the pure-mojo stdio helper from vfork to fork before exec
- use _exit in the child failure path to avoid runtime teardown behavior
- capture raw fd and argv state before spawning so the child stays primitive-only
- keep the direct daemon process lane green across repo-local and mounted tests
Diffstat:
1 file changed, 29 insertions(+), 15 deletions(-)
diff --git a/tests/stdio_process_helper.mojo b/tests/stdio_process_helper.mojo
@@ -1,7 +1,7 @@
import std.os
from std.os import Pipe, Process
from std.ffi import CStringSlice, c_int, external_call
-from std.sys._libc import close, exit, vfork
+from std.sys._libc import close
from std.tempfile import TemporaryDirectory
from mojson import Value, loads
@@ -37,6 +37,16 @@ def _dup2(oldfd: c_int, newfd: c_int) -> c_int:
return external_call["dup2", c_int](oldfd, newfd)
+@always_inline
+def _fork() -> c_int:
+ return external_call["fork", c_int]()
+
+
+@always_inline
+def _exit_child(code: c_int):
+ _ = external_call["_exit", c_int](code)
+
+
def _read_pipe_to_string(mut pipe: Pipe) raises -> String:
var buffer = InlineArray[Byte, 4096](fill=0)
var output = String("")
@@ -97,24 +107,28 @@ def run_stdio_entrypoint_with_2_args(
process_arg1.as_c_string_slice()
)
- var pid = vfork()
+ var stdin_read_fd = c_int(stdin_pipe.fd_in.value().value)
+ var stdin_write_fd = c_int(stdin_pipe.fd_out.value().value)
+ var stdout_read_fd = c_int(stdout_pipe.fd_in.value().value)
+ var stdout_write_fd = c_int(stdout_pipe.fd_out.value().value)
+ var command_ptr = command.as_c_string_slice().unsafe_ptr()
+ var argv_ptr = argv.unsafe_ptr()
+
+ var pid = _fork()
if pid < 0:
raise Error("failed to spawn hyf process test child")
if pid == 0:
- if _dup2(c_int(stdin_pipe.fd_in.value().value), 0) < 0:
- exit(126)
- if _dup2(c_int(stdout_pipe.fd_out.value().value), 1) < 0:
- exit(126)
- _ = close(c_int(stdin_pipe.fd_in.value().value))
- _ = close(c_int(stdin_pipe.fd_out.value().value))
- _ = close(c_int(stdout_pipe.fd_in.value().value))
- _ = close(c_int(stdout_pipe.fd_out.value().value))
- _ = external_call["execvp", c_int](
- command.as_c_string_slice().unsafe_ptr(),
- argv.unsafe_ptr(),
- )
- exit(127)
+ if _dup2(stdin_read_fd, 0) < 0:
+ _exit_child(c_int(126))
+ if _dup2(stdout_write_fd, 1) < 0:
+ _exit_child(c_int(126))
+ _ = close(stdin_read_fd)
+ _ = close(stdin_write_fd)
+ _ = close(stdout_read_fd)
+ _ = close(stdout_write_fd)
+ _ = external_call["execvp", c_int](command_ptr, argv_ptr)
+ _exit_child(c_int(127))
stdin_pipe.set_output_only()
stdout_pipe.set_input_only()