@@ -57,12 +57,6 @@ pub const ChildProcess = struct {
5757
5858 expand_arg0 : Arg0Expand ,
5959
60- /// Use this for additional posix spawn attributes.
61- /// Do not set spawn attribute flags and do not modify stdin, stdout, stderr
62- /// behavior, because those are set in the platform-specific spawn method.
63- posix_attr : if (os .hasPosixSpawn ) ? os .posix_spawn .Attr else void ,
64- posix_actions : if (os .hasPosixSpawn ) ? os .posix_spawn .Actions else void ,
65-
6660 /// Darwin-only. Disable ASLR for the child process.
6761 disable_aslr : bool = false ,
6862
@@ -132,8 +126,6 @@ pub const ChildProcess = struct {
132126 .stdout_behavior = StdIo .Inherit ,
133127 .stderr_behavior = StdIo .Inherit ,
134128 .expand_arg0 = .no_expand ,
135- .posix_attr = if (os .hasPosixSpawn ) null else undefined ,
136- .posix_actions = if (os .hasPosixSpawn ) null else undefined ,
137129 };
138130 }
139131
@@ -149,7 +141,7 @@ pub const ChildProcess = struct {
149141 @compileError ("the target operating system cannot spawn processes" );
150142 }
151143
152- if (os . hasPosixSpawn ) {
144+ if (comptime builtin . target . isDarwin () ) {
153145 return self .spawnMacos ();
154146 }
155147
@@ -481,7 +473,7 @@ pub const ChildProcess = struct {
481473 }
482474
483475 fn waitUnwrapped (self : * ChildProcess ) ! void {
484- const res : os.WaitPidResult = if (os . hasPosixSpawn )
476+ const res : os.WaitPidResult = if (comptime builtin . target . isDarwin () )
485477 try os .posix_spawn .waitpid (self .pid , 0 )
486478 else
487479 os .waitpid (self .pid , 0 );
@@ -561,10 +553,6 @@ pub const ChildProcess = struct {
561553 }
562554
563555 fn spawnMacos (self : * ChildProcess ) SpawnError ! void {
564- // dont cleanup structure owned == initialized by user
565- const user_attr : bool = self .posix_attr != null ;
566- const user_actions : bool = self .posix_actions != null ;
567-
568556 const pipe_flags = if (io .is_async ) os .O .NONBLOCK else 0 ;
569557 const stdin_pipe = if (self .stdin_behavior == StdIo .Pipe ) try os .pipe2 (pipe_flags ) else undefined ;
570558 errdefer if (self .stdin_behavior == StdIo .Pipe ) destroyPipe (stdin_pipe );
@@ -592,28 +580,28 @@ pub const ChildProcess = struct {
592580 undefined ;
593581 defer if (any_ignore ) os .close (dev_null_fd );
594582
595- if ( user_attr == false ) self . posix_attr = try os .posix_spawn .Attr .init ();
596- defer if ( user_attr == false ) self . posix_attr .? .deinit ();
583+ var attr = try os .posix_spawn .Attr .init ();
584+ defer attr .deinit ();
597585 var flags : u16 = os .darwin .POSIX_SPAWN_SETSIGDEF | os .darwin .POSIX_SPAWN_SETSIGMASK ;
598586 if (self .disable_aslr ) {
599587 flags |= os .darwin ._POSIX_SPAWN_DISABLE_ASLR ;
600588 }
601589 if (self .start_suspended ) {
602590 flags |= os .darwin .POSIX_SPAWN_START_SUSPENDED ;
603591 }
604- try self . posix_attr .? .set (flags );
592+ try attr .set (flags );
605593
606- if ( user_actions == false ) self . posix_actions = try os .posix_spawn .Actions .init ();
607- defer if ( user_actions == false ) self . posix_actions .? .deinit ();
594+ var actions = try os .posix_spawn .Actions .init ();
595+ defer actions .deinit ();
608596
609- try setUpChildIoPosixSpawn (self .stdin_behavior , & self . posix_actions .? , stdin_pipe , os .STDIN_FILENO , dev_null_fd );
610- try setUpChildIoPosixSpawn (self .stdout_behavior , & self . posix_actions .? , stdout_pipe , os .STDOUT_FILENO , dev_null_fd );
611- try setUpChildIoPosixSpawn (self .stderr_behavior , & self . posix_actions .? , stderr_pipe , os .STDERR_FILENO , dev_null_fd );
597+ try setUpChildIoPosixSpawn (self .stdin_behavior , & actions , stdin_pipe , os .STDIN_FILENO , dev_null_fd );
598+ try setUpChildIoPosixSpawn (self .stdout_behavior , & actions , stdout_pipe , os .STDOUT_FILENO , dev_null_fd );
599+ try setUpChildIoPosixSpawn (self .stderr_behavior , & actions , stderr_pipe , os .STDERR_FILENO , dev_null_fd );
612600
613601 if (self .cwd_dir ) | cwd | {
614- try self . posix_actions .? .fchdir (cwd .fd );
602+ try actions .fchdir (cwd .fd );
615603 } else if (self .cwd ) | cwd | {
616- try self . posix_actions .? .chdir (cwd );
604+ try actions .chdir (cwd );
617605 }
618606
619607 var arena_allocator = std .heap .ArenaAllocator .init (self .allocator );
@@ -628,7 +616,7 @@ pub const ChildProcess = struct {
628616 break :m envp_buf .ptr ;
629617 } else std .c .environ ;
630618
631- const pid = try os .posix_spawn .spawnp (self .argv [0 ], self . posix_actions .? , self . posix_attr .? , argv_buf , envp );
619+ const pid = try os .posix_spawn .spawnp (self .argv [0 ], actions , attr , argv_buf , envp );
632620
633621 if (self .stdin_behavior == StdIo .Pipe ) {
634622 self .stdin = File { .handle = stdin_pipe [1 ] };
0 commit comments