From 150031b9838d7337d83ebd59c9d2c521a5633555 Mon Sep 17 00:00:00 2001 From: Misaki Kasumi Date: Wed, 1 Jan 2025 12:45:57 +0800 Subject: [PATCH] std.os.linux: accept u8 in sigaction --- lib/std/os/linux.zig | 23 ++++++++++------------- lib/std/process/Child.zig | 9 --------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 32070e5a03e9..5b118fb56362 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -1744,24 +1744,21 @@ pub fn sigprocmask(flags: u32, noalias set: ?*const sigset_t, noalias oldset: ?* return syscall4(.rt_sigprocmask, flags, @intFromPtr(set), @intFromPtr(oldset), NSIG / 8); } -pub fn sigaction(sig: u6, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) usize { - assert(sig >= 1); - assert(sig != SIG.KILL); - assert(sig != SIG.STOP); - +pub fn sigaction(sig: u8, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) usize { var ksa: k_sigaction = undefined; var oldksa: k_sigaction = undefined; const mask_size = @sizeOf(@TypeOf(ksa.mask)); if (act) |new| { - const restorer_fn = if ((new.flags & SA.SIGINFO) != 0) &restore_rt else &restore; - ksa = k_sigaction{ - .handler = new.handler.handler, - .flags = new.flags | SA.RESTORER, - .mask = undefined, - .restorer = @ptrCast(restorer_fn), - }; - @memcpy(@as([*]u8, @ptrCast(&ksa.mask))[0..mask_size], @as([*]const u8, @ptrCast(&new.mask))); + ksa.handler = new.handler.handler; + if (ksa.handler == SIG.DFL or ksa.handler == SIG.IGN) { + ksa.flags = new.flags; + } else { + const restorer_fn = if ((new.flags & SA.SIGINFO) != 0) &restore_rt else &restore; + ksa.flags = new.flags | SA.RESTORER; + ksa.restorer = @ptrCast(restorer_fn); + @memcpy(@as([*]u8, @ptrCast(&ksa.mask))[0..mask_size], @as([*]const u8, @ptrCast(&new.mask))); + } } const ksa_arg = if (act != null) @intFromPtr(&ksa) else 0; diff --git a/lib/std/process/Child.zig b/lib/std/process/Child.zig index 1bc31f5fe985..da512b7c15bd 100644 --- a/lib/std/process/Child.zig +++ b/lib/std/process/Child.zig @@ -571,17 +571,8 @@ fn spawnPosixChildHelper(arg: usize) callconv(.c) u8 { if (native_os == .linux and child_arg.sigmask != null) { std.debug.assert(linux.SIG.DFL == null); for (1..linux.NSIG) |sig| { - if (sig == posix.SIG.KILL or sig == posix.SIG.STOP) { - continue; - } - if (sig > std.math.maxInt(u6)) { - // XXX: We cannot disable all signals. - // sigaction accepts u6, which is too narrow. - break; - } var old_act: posix.Sigaction = undefined; const new_act = mem.zeroes(posix.Sigaction); - // Do not use posix.sigaction. It reaches unreachable. _ = linux.sigaction(@intCast(sig), &new_act, &old_act); if (old_act.handler.handler == linux.SIG.IGN) { _ = linux.sigaction(@intCast(sig), &old_act, null);