Skip to content

Commit 6a3e64b

Browse files
committed
std.process.Child: Fix stage2_c
1 parent 4c7fd77 commit 6a3e64b

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/std/process/Child.zig

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const native_os = builtin.os.tag;
1515
const Allocator = std.mem.Allocator;
1616
const ChildProcess = @This();
1717

18+
const use_clone = native_os == .linux and builtin.zig_backend != .stage2_c;
19+
1820
pub const Id = switch (native_os) {
1921
.windows => windows.HANDLE,
2022
.wasi => void,
@@ -73,7 +75,7 @@ cwd: ?[]const u8,
7375
/// Once that is done, `cwd` will be deprecated in favor of this field.
7476
cwd_dir: ?fs.Dir = null,
7577

76-
err_pipe: ?if (native_os == .windows or native_os == .linux) void else [2]posix.fd_t,
78+
err_pipe: ?if (native_os == .windows or use_clone) void else [2]posix.fd_t,
7779

7880
expand_arg0: Arg0Expand,
7981

@@ -488,7 +490,7 @@ fn cleanupStreams(self: *ChildProcess) void {
488490
}
489491

490492
fn cleanupAfterWait(self: *ChildProcess, status: u32) !Term {
491-
if (native_os != .linux) {
493+
if (!use_clone) {
492494
if (self.err_pipe) |err_pipe| {
493495
defer destroyPipe(err_pipe);
494496

@@ -521,7 +523,7 @@ fn statusToTerm(status: u32) Term {
521523
Term{ .Unknown = status };
522524
}
523525

524-
const RetErr = if (native_os == .linux) ?SpawnError else posix.fd_t;
526+
const RetErr = if (use_clone) ?SpawnError else posix.fd_t;
525527

526528
const ChildArg = struct {
527529
self: *ChildProcess,
@@ -673,7 +675,7 @@ fn spawnPosix(self: *ChildProcess) SpawnError!void {
673675
// This pipe is used to communicate errors between the time of fork
674676
// and execve from the child process to the parent process.
675677
const err_pipe = blk: {
676-
if (native_os != .linux) {
678+
if (!use_clone) {
677679
break :blk try posix.pipe2(.{ .CLOEXEC = true });
678680
} else {
679681
break :blk [_]posix.fd_t{ -1, -1 };
@@ -694,7 +696,7 @@ fn spawnPosix(self: *ChildProcess) SpawnError!void {
694696
};
695697

696698
var pid_result: posix.pid_t = undefined;
697-
if (native_os != .linux) {
699+
if (!use_clone) {
698700
child_arg.ret_err = err_pipe[1];
699701
pid_result = try posix.fork();
700702
if (pid_result == 0) {
@@ -739,7 +741,7 @@ fn spawnPosix(self: *ChildProcess) SpawnError!void {
739741
}
740742

741743
self.id = pid;
742-
if (native_os != .linux or builtin.zig_backend == .stage2_c) {
744+
if (!use_clone) {
743745
self.err_pipe = err_pipe;
744746
}
745747
self.term = null;
@@ -1063,7 +1065,7 @@ fn immediateExit(exitcode: u8) noreturn {
10631065
// Child of fork calls this to report an error to the fork parent.
10641066
// Returns exit code.
10651067
fn forkChildErrReport(retErr: *RetErr, err: ChildProcess.SpawnError) u8 {
1066-
if (native_os != .linux) {
1068+
if (!use_clone) {
10671069
writeIntFd(retErr.*, @as(ErrInt, @intFromError(err))) catch {};
10681070
} else {
10691071
retErr.* = err;

0 commit comments

Comments
 (0)