@@ -5,6 +5,7 @@ const unicode = std.unicode;
5
5
const io = std .io ;
6
6
const fs = std .fs ;
7
7
const os = std .os ;
8
+ const posix = os .posix ;
8
9
const process = std .process ;
9
10
const File = std .fs .File ;
10
11
const windows = os .windows ;
@@ -70,7 +71,7 @@ pub const ChildProcess = struct {
70
71
/// Darwin-only. Start child process in suspended state as if SIGSTOP was sent.
71
72
start_suspended : bool = false ,
72
73
73
- pub const Arg0Expand = os .Arg0Expand ;
74
+ pub const Arg0Expand = os .posix . Arg0Expand ;
74
75
75
76
pub const SpawnError = error {
76
77
OutOfMemory ,
@@ -86,8 +87,8 @@ pub const ChildProcess = struct {
86
87
/// Windows-only. `cwd` was provided, but the path did not exist when spawning the child process.
87
88
CurrentWorkingDirectoryUnlinked ,
88
89
} ||
89
- os .ExecveError ||
90
- os .SetIdError ||
90
+ os .posix . ExecveError ||
91
+ os .posix . SetIdError ||
91
92
os .ChangeCurDirError ||
92
93
windows .CreateProcessError ||
93
94
windows .WaitForSingleObjectError ||
@@ -184,7 +185,7 @@ pub const ChildProcess = struct {
184
185
self .cleanupStreams ();
185
186
return term ;
186
187
}
187
- try os .kill (self .id , os .SIG .TERM );
188
+ try posix .kill (self .pid , os .SIG .TERM );
188
189
try self .waitUnwrapped ();
189
190
return self .term .? ;
190
191
}
@@ -314,7 +315,7 @@ pub const ChildProcess = struct {
314
315
return term ;
315
316
}
316
317
317
- try self .waitUnwrapped ();
318
+ try self .waitUnwrappedPosix ();
318
319
return self .term .? ;
319
320
}
320
321
@@ -336,11 +337,11 @@ pub const ChildProcess = struct {
336
337
return result ;
337
338
}
338
339
339
- fn waitUnwrapped (self : * ChildProcess ) ! void {
340
- const res : os.WaitPidResult = if (comptime builtin .target .isDarwin ())
340
+ fn waitUnwrappedPosix (self : * ChildProcess ) ! void {
341
+ const res : os.posix. WaitPidResult = if (comptime builtin .target .isDarwin ())
341
342
try os .posix_spawn .waitpid (self .id , 0 )
342
343
else
343
- os .waitpid (self .id , 0 );
344
+ os .posix . waitpid (self .id , 0 );
344
345
const status = res .status ;
345
346
self .cleanupStreams ();
346
347
self .handleWaitResult (status );
@@ -418,13 +419,13 @@ pub const ChildProcess = struct {
418
419
419
420
fn spawnMacos (self : * ChildProcess ) SpawnError ! void {
420
421
const pipe_flags = if (io .is_async ) os .O .NONBLOCK else 0 ;
421
- const stdin_pipe = if (self .stdin_behavior == StdIo .Pipe ) try os .pipe2 (pipe_flags ) else undefined ;
422
+ const stdin_pipe = if (self .stdin_behavior == StdIo .Pipe ) try os .posix . pipe2 (pipe_flags ) else undefined ;
422
423
errdefer if (self .stdin_behavior == StdIo .Pipe ) destroyPipe (stdin_pipe );
423
424
424
- const stdout_pipe = if (self .stdout_behavior == StdIo .Pipe ) try os .pipe2 (pipe_flags ) else undefined ;
425
+ const stdout_pipe = if (self .stdout_behavior == StdIo .Pipe ) try os .posix . pipe2 (pipe_flags ) else undefined ;
425
426
errdefer if (self .stdout_behavior == StdIo .Pipe ) destroyPipe (stdout_pipe );
426
427
427
- const stderr_pipe = if (self .stderr_behavior == StdIo .Pipe ) try os .pipe2 (pipe_flags ) else undefined ;
428
+ const stderr_pipe = if (self .stderr_behavior == StdIo .Pipe ) try os .posix . pipe2 (pipe_flags ) else undefined ;
428
429
errdefer if (self .stderr_behavior == StdIo .Pipe ) destroyPipe (stderr_pipe );
429
430
430
431
const any_ignore = (self .stdin_behavior == StdIo .Ignore or self .stdout_behavior == StdIo .Ignore or self .stderr_behavior == StdIo .Ignore );
@@ -533,17 +534,17 @@ pub const ChildProcess = struct {
533
534
534
535
fn spawnPosix (self : * ChildProcess ) SpawnError ! void {
535
536
const pipe_flags = if (io .is_async ) os .O .NONBLOCK else 0 ;
536
- const stdin_pipe = if (self .stdin_behavior == StdIo .Pipe ) try os .pipe2 (pipe_flags ) else undefined ;
537
+ const stdin_pipe = if (self .stdin_behavior == StdIo .Pipe ) try os .posix . pipe2 (pipe_flags ) else undefined ;
537
538
errdefer if (self .stdin_behavior == StdIo .Pipe ) {
538
539
destroyPipe (stdin_pipe );
539
540
};
540
541
541
- const stdout_pipe = if (self .stdout_behavior == StdIo .Pipe ) try os .pipe2 (pipe_flags ) else undefined ;
542
+ const stdout_pipe = if (self .stdout_behavior == StdIo .Pipe ) try os .posix . pipe2 (pipe_flags ) else undefined ;
542
543
errdefer if (self .stdout_behavior == StdIo .Pipe ) {
543
544
destroyPipe (stdout_pipe );
544
545
};
545
546
546
- const stderr_pipe = if (self .stderr_behavior == StdIo .Pipe ) try os .pipe2 (pipe_flags ) else undefined ;
547
+ const stderr_pipe = if (self .stderr_behavior == StdIo .Pipe ) try os .posix . pipe2 (pipe_flags ) else undefined ;
547
548
errdefer if (self .stderr_behavior == StdIo .Pipe ) {
548
549
destroyPipe (stderr_pipe );
549
550
};
@@ -608,12 +609,12 @@ pub const ChildProcess = struct {
608
609
// end with eventfd
609
610
break :blk [2 ]os.fd_t { fd , fd };
610
611
} else {
611
- break :blk try os .pipe2 (os .O .CLOEXEC );
612
+ break :blk try os .posix . pipe2 (os .O .CLOEXEC );
612
613
}
613
614
};
614
615
errdefer destroyPipe (err_pipe );
615
616
616
- const pid_result = try os .fork ();
617
+ const pid_result = try os .posix . fork ();
617
618
if (pid_result == 0 ) {
618
619
// we are the child
619
620
setUpChildIo (self .stdin_behavior , stdin_pipe [0 ], os .STDIN_FILENO , dev_null_fd ) catch | err | forkChildErrReport (err_pipe [1 ], err );
@@ -640,16 +641,16 @@ pub const ChildProcess = struct {
640
641
}
641
642
642
643
if (self .gid ) | gid | {
643
- os .setregid (gid , gid ) catch | err | forkChildErrReport (err_pipe [1 ], err );
644
+ os .posix . setregid (gid , gid ) catch | err | forkChildErrReport (err_pipe [1 ], err );
644
645
}
645
646
646
647
if (self .uid ) | uid | {
647
- os .setreuid (uid , uid ) catch | err | forkChildErrReport (err_pipe [1 ], err );
648
+ os .posix . setreuid (uid , uid ) catch | err | forkChildErrReport (err_pipe [1 ], err );
648
649
}
649
650
650
651
const err = switch (self .expand_arg0 ) {
651
- .expand = > os .execvpeZ_expandArg0 (.expand , argv_buf .ptr [0 ].? , argv_buf .ptr , envp ),
652
- .no_expand = > os .execvpeZ_expandArg0 (.no_expand , argv_buf .ptr [0 ].? , argv_buf .ptr , envp ),
652
+ .expand = > os .posix . execvpeZ_expandArg0 (.expand , argv_buf .ptr [0 ].? , argv_buf .ptr , envp ),
653
+ .no_expand = > os .posix . execvpeZ_expandArg0 (.no_expand , argv_buf .ptr [0 ].? , argv_buf .ptr , envp ),
653
654
};
654
655
forkChildErrReport (err_pipe [1 ], err );
655
656
}
@@ -955,10 +956,10 @@ pub const ChildProcess = struct {
955
956
956
957
fn setUpChildIo (stdio : StdIo , pipe_fd : i32 , std_fileno : i32 , dev_null_fd : i32 ) ! void {
957
958
switch (stdio ) {
958
- .Pipe = > try os .dup2 (pipe_fd , std_fileno ),
959
+ .Pipe = > try os .posix . dup2 (pipe_fd , std_fileno ),
959
960
.Close = > os .close (std_fileno ),
960
961
.Inherit = > {},
961
- .Ignore = > try os .dup2 (dev_null_fd , std_fileno ),
962
+ .Ignore = > try os .posix . dup2 (dev_null_fd , std_fileno ),
962
963
}
963
964
}
964
965
};
0 commit comments