@@ -15,6 +15,8 @@ const native_os = builtin.os.tag;
15
15
const Allocator = std .mem .Allocator ;
16
16
const ChildProcess = @This ();
17
17
18
+ const use_clone = native_os == .linux and builtin .zig_backend != .stage2_c ;
19
+
18
20
pub const Id = switch (native_os ) {
19
21
.windows = > windows .HANDLE ,
20
22
.wasi = > void ,
@@ -73,7 +75,7 @@ cwd: ?[]const u8,
73
75
/// Once that is done, `cwd` will be deprecated in favor of this field.
74
76
cwd_dir : ? fs.Dir = null ,
75
77
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 ,
77
79
78
80
expand_arg0 : Arg0Expand ,
79
81
@@ -488,7 +490,7 @@ fn cleanupStreams(self: *ChildProcess) void {
488
490
}
489
491
490
492
fn cleanupAfterWait (self : * ChildProcess , status : u32 ) ! Term {
491
- if (native_os != .linux ) {
493
+ if (! use_clone ) {
492
494
if (self .err_pipe ) | err_pipe | {
493
495
defer destroyPipe (err_pipe );
494
496
@@ -521,7 +523,7 @@ fn statusToTerm(status: u32) Term {
521
523
Term { .Unknown = status };
522
524
}
523
525
524
- const RetErr = if (native_os == .linux ) ? SpawnError else posix .fd_t ;
526
+ const RetErr = if (use_clone ) ? SpawnError else posix .fd_t ;
525
527
526
528
const ChildArg = struct {
527
529
self : * ChildProcess ,
@@ -673,7 +675,7 @@ fn spawnPosix(self: *ChildProcess) SpawnError!void {
673
675
// This pipe is used to communicate errors between the time of fork
674
676
// and execve from the child process to the parent process.
675
677
const err_pipe = blk : {
676
- if (native_os != .linux ) {
678
+ if (! use_clone ) {
677
679
break :blk try posix .pipe2 (.{ .CLOEXEC = true });
678
680
} else {
679
681
break :blk [_ ]posix.fd_t { -1 , -1 };
@@ -694,7 +696,7 @@ fn spawnPosix(self: *ChildProcess) SpawnError!void {
694
696
};
695
697
696
698
var pid_result : posix.pid_t = undefined ;
697
- if (native_os != .linux ) {
699
+ if (! use_clone ) {
698
700
child_arg .ret_err = err_pipe [1 ];
699
701
pid_result = try posix .fork ();
700
702
if (pid_result == 0 ) {
@@ -739,7 +741,7 @@ fn spawnPosix(self: *ChildProcess) SpawnError!void {
739
741
}
740
742
741
743
self .id = pid ;
742
- if (native_os != .linux or builtin . zig_backend == .stage2_c ) {
744
+ if (! use_clone ) {
743
745
self .err_pipe = err_pipe ;
744
746
}
745
747
self .term = null ;
@@ -1063,7 +1065,7 @@ fn immediateExit(exitcode: u8) noreturn {
1063
1065
// Child of fork calls this to report an error to the fork parent.
1064
1066
// Returns exit code.
1065
1067
fn forkChildErrReport (retErr : * RetErr , err : ChildProcess.SpawnError ) u8 {
1066
- if (native_os != .linux ) {
1068
+ if (! use_clone ) {
1067
1069
writeIntFd (retErr .* , @as (ErrInt , @intFromError (err ))) catch {};
1068
1070
} else {
1069
1071
retErr .* = err ;
0 commit comments