@@ -532,6 +532,7 @@ const ChildArg = struct {
532
532
dev_null_fd : posix.fd_t ,
533
533
argv_buf : [:null ]? [* :0 ]const u8 ,
534
534
envp : [* :null ]const ? [* :0 ]const u8 ,
535
+ sigmask : ? * posix.sigset_t ,
535
536
ret_err : RetErr ,
536
537
};
537
538
@@ -565,6 +566,27 @@ fn spawnPosixChildHelper(arg: usize) callconv(.c) u8 {
565
566
posix .setpgid (0 , pid ) catch | err | return forkChildErrReport (& child_arg .ret_err , err );
566
567
}
567
568
569
+ if (native_os == .linux and child_arg .sigmask != null ) {
570
+ std .debug .assert (linux .SIG .DFL == null );
571
+ for (1.. linux .NSIG ) | sig | {
572
+ if (sig == posix .SIG .KILL or sig == posix .SIG .STOP ) {
573
+ continue ;
574
+ }
575
+ if (sig > std .math .maxInt (u6 )) {
576
+ // XXX: We cannot disable all signals.
577
+ // sigaction accepts u6, which is too narrow.
578
+ break ;
579
+ }
580
+ var old_act : posix.Sigaction = undefined ;
581
+ const new_act = mem .zeroes (posix .Sigaction );
582
+ posix .sigaction (@intCast (sig ), & new_act , & old_act );
583
+ if (old_act .handler .handler == linux .SIG .IGN ) {
584
+ posix .sigaction (@intCast (sig ), & old_act , null );
585
+ }
586
+ }
587
+ posix .sigprocmask (posix .SIG .SETMASK , child_arg .sigmask , null );
588
+ }
589
+
568
590
const err = switch (child_arg .self .expand_arg0 ) {
569
591
.expand = > posix .execvpeZ_expandArg0 (.expand , child_arg .argv_buf .ptr [0 ].? , child_arg .argv_buf .ptr , child_arg .envp ),
570
592
.no_expand = > posix .execvpeZ_expandArg0 (.no_expand , child_arg .argv_buf .ptr [0 ].? , child_arg .argv_buf .ptr , child_arg .envp ),
@@ -690,6 +712,7 @@ fn spawnPosix(self: *ChildProcess) SpawnError!void {
690
712
.dev_null_fd = dev_null_fd ,
691
713
.argv_buf = argv_buf ,
692
714
.envp = envp ,
715
+ .sigmask = null ,
693
716
.ret_err = undefined ,
694
717
};
695
718
@@ -701,6 +724,10 @@ fn spawnPosix(self: *ChildProcess) SpawnError!void {
701
724
immediateExit (spawnPosixChildHelper (@intFromPtr (& child_arg )));
702
725
}
703
726
} else {
727
+ var old_mask : posix.sigset_t = undefined ;
728
+ posix .sigprocmask (posix .SIG .SETMASK , & linux .all_mask , & old_mask );
729
+ defer posix .sigprocmask (posix .SIG .SETMASK , & old_mask , null );
730
+ child_arg .sigmask = & old_mask ;
704
731
child_arg .ret_err = null ;
705
732
// Although the stack is fixed sized, we alloc it here,
706
733
// because stack-smashing protection may have higher overhead than allocation.
0 commit comments