@@ -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 ;
@@ -179,7 +180,7 @@ pub const ChildProcess = struct {
179
180
self .cleanupStreams ();
180
181
return term ;
181
182
}
182
- try os .kill (self .id , os .SIG .TERM );
183
+ try posix .kill (self .pid , os .SIG .TERM );
183
184
try self .waitUnwrapped ();
184
185
return self .term .? ;
185
186
}
@@ -309,7 +310,7 @@ pub const ChildProcess = struct {
309
310
return term ;
310
311
}
311
312
312
- try self .waitUnwrapped ();
313
+ try self .waitUnwrappedPosix ();
313
314
return self .term .? ;
314
315
}
315
316
@@ -331,8 +332,8 @@ pub const ChildProcess = struct {
331
332
return result ;
332
333
}
333
334
334
- fn waitUnwrapped (self : * ChildProcess ) ! void {
335
- const res : os.WaitPidResult = os .waitpid (self .id , 0 );
335
+ fn waitUnwrappedPosix (self : * ChildProcess ) ! void {
336
+ const res : os.posix. WaitPidResult = os . posix .waitpid (self .id , 0 );
336
337
const status = res .status ;
337
338
self .cleanupStreams ();
338
339
self .handleWaitResult (status );
@@ -410,17 +411,17 @@ pub const ChildProcess = struct {
410
411
411
412
fn spawnPosix (self : * ChildProcess ) SpawnError ! void {
412
413
const pipe_flags = if (io .is_async ) os .O .NONBLOCK else 0 ;
413
- const stdin_pipe = if (self .stdin_behavior == StdIo .Pipe ) try os .pipe2 (pipe_flags ) else undefined ;
414
+ const stdin_pipe = if (self .stdin_behavior == StdIo .Pipe ) try os .posix . pipe2 (pipe_flags ) else undefined ;
414
415
errdefer if (self .stdin_behavior == StdIo .Pipe ) {
415
416
destroyPipe (stdin_pipe );
416
417
};
417
418
418
- const stdout_pipe = if (self .stdout_behavior == StdIo .Pipe ) try os .pipe2 (pipe_flags ) else undefined ;
419
+ const stdout_pipe = if (self .stdout_behavior == StdIo .Pipe ) try os .posix . pipe2 (pipe_flags ) else undefined ;
419
420
errdefer if (self .stdout_behavior == StdIo .Pipe ) {
420
421
destroyPipe (stdout_pipe );
421
422
};
422
423
423
- const stderr_pipe = if (self .stderr_behavior == StdIo .Pipe ) try os .pipe2 (pipe_flags ) else undefined ;
424
+ const stderr_pipe = if (self .stderr_behavior == StdIo .Pipe ) try os .posix . pipe2 (pipe_flags ) else undefined ;
424
425
errdefer if (self .stderr_behavior == StdIo .Pipe ) {
425
426
destroyPipe (stderr_pipe );
426
427
};
@@ -485,12 +486,12 @@ pub const ChildProcess = struct {
485
486
// end with eventfd
486
487
break :blk [2 ]os.fd_t { fd , fd };
487
488
} else {
488
- break :blk try os .pipe2 (os .O .CLOEXEC );
489
+ break :blk try os .posix . pipe2 (os .O .CLOEXEC );
489
490
}
490
491
};
491
492
errdefer destroyPipe (err_pipe );
492
493
493
- const pid_result = try os .fork ();
494
+ const pid_result = try os .posix . fork ();
494
495
if (pid_result == 0 ) {
495
496
// we are the child
496
497
setUpChildIo (self .stdin_behavior , stdin_pipe [0 ], os .STDIN_FILENO , dev_null_fd ) catch | err | forkChildErrReport (err_pipe [1 ], err );
@@ -517,16 +518,16 @@ pub const ChildProcess = struct {
517
518
}
518
519
519
520
if (self .gid ) | gid | {
520
- os .setregid (gid , gid ) catch | err | forkChildErrReport (err_pipe [1 ], err );
521
+ os .posix . setregid (gid , gid ) catch | err | forkChildErrReport (err_pipe [1 ], err );
521
522
}
522
523
523
524
if (self .uid ) | uid | {
524
- os .setreuid (uid , uid ) catch | err | forkChildErrReport (err_pipe [1 ], err );
525
+ os .posix . setreuid (uid , uid ) catch | err | forkChildErrReport (err_pipe [1 ], err );
525
526
}
526
527
527
528
const err = switch (self .expand_arg0 ) {
528
- .expand = > os .execvpeZ_expandArg0 (.expand , argv_buf .ptr [0 ].? , argv_buf .ptr , envp ),
529
- .no_expand = > os .execvpeZ_expandArg0 (.no_expand , argv_buf .ptr [0 ].? , argv_buf .ptr , envp ),
529
+ .expand = > os .posix . execvpeZ_expandArg0 (.expand , argv_buf .ptr [0 ].? , argv_buf .ptr , envp ),
530
+ .no_expand = > os .posix . execvpeZ_expandArg0 (.no_expand , argv_buf .ptr [0 ].? , argv_buf .ptr , envp ),
530
531
};
531
532
forkChildErrReport (err_pipe [1 ], err );
532
533
}
@@ -832,10 +833,10 @@ pub const ChildProcess = struct {
832
833
833
834
fn setUpChildIo (stdio : StdIo , pipe_fd : i32 , std_fileno : i32 , dev_null_fd : i32 ) ! void {
834
835
switch (stdio ) {
835
- .Pipe = > try os .dup2 (pipe_fd , std_fileno ),
836
+ .Pipe = > try os .posix . dup2 (pipe_fd , std_fileno ),
836
837
.Close = > os .close (std_fileno ),
837
838
.Inherit = > {},
838
- .Ignore = > try os .dup2 (dev_null_fd , std_fileno ),
839
+ .Ignore = > try os .posix . dup2 (dev_null_fd , std_fileno ),
839
840
}
840
841
}
841
842
};
0 commit comments