Skip to content

Commit 150031b

Browse files
committed
std.os.linux: accept u8 in sigaction
1 parent 132cb97 commit 150031b

File tree

2 files changed

+10
-22
lines changed

2 files changed

+10
-22
lines changed

lib/std/os/linux.zig

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,24 +1744,21 @@ pub fn sigprocmask(flags: u32, noalias set: ?*const sigset_t, noalias oldset: ?*
17441744
return syscall4(.rt_sigprocmask, flags, @intFromPtr(set), @intFromPtr(oldset), NSIG / 8);
17451745
}
17461746

1747-
pub fn sigaction(sig: u6, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) usize {
1748-
assert(sig >= 1);
1749-
assert(sig != SIG.KILL);
1750-
assert(sig != SIG.STOP);
1751-
1747+
pub fn sigaction(sig: u8, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) usize {
17521748
var ksa: k_sigaction = undefined;
17531749
var oldksa: k_sigaction = undefined;
17541750
const mask_size = @sizeOf(@TypeOf(ksa.mask));
17551751

17561752
if (act) |new| {
1757-
const restorer_fn = if ((new.flags & SA.SIGINFO) != 0) &restore_rt else &restore;
1758-
ksa = k_sigaction{
1759-
.handler = new.handler.handler,
1760-
.flags = new.flags | SA.RESTORER,
1761-
.mask = undefined,
1762-
.restorer = @ptrCast(restorer_fn),
1763-
};
1764-
@memcpy(@as([*]u8, @ptrCast(&ksa.mask))[0..mask_size], @as([*]const u8, @ptrCast(&new.mask)));
1753+
ksa.handler = new.handler.handler;
1754+
if (ksa.handler == SIG.DFL or ksa.handler == SIG.IGN) {
1755+
ksa.flags = new.flags;
1756+
} else {
1757+
const restorer_fn = if ((new.flags & SA.SIGINFO) != 0) &restore_rt else &restore;
1758+
ksa.flags = new.flags | SA.RESTORER;
1759+
ksa.restorer = @ptrCast(restorer_fn);
1760+
@memcpy(@as([*]u8, @ptrCast(&ksa.mask))[0..mask_size], @as([*]const u8, @ptrCast(&new.mask)));
1761+
}
17651762
}
17661763

17671764
const ksa_arg = if (act != null) @intFromPtr(&ksa) else 0;

lib/std/process/Child.zig

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -571,17 +571,8 @@ fn spawnPosixChildHelper(arg: usize) callconv(.c) u8 {
571571
if (native_os == .linux and child_arg.sigmask != null) {
572572
std.debug.assert(linux.SIG.DFL == null);
573573
for (1..linux.NSIG) |sig| {
574-
if (sig == posix.SIG.KILL or sig == posix.SIG.STOP) {
575-
continue;
576-
}
577-
if (sig > std.math.maxInt(u6)) {
578-
// XXX: We cannot disable all signals.
579-
// sigaction accepts u6, which is too narrow.
580-
break;
581-
}
582574
var old_act: posix.Sigaction = undefined;
583575
const new_act = mem.zeroes(posix.Sigaction);
584-
// Do not use posix.sigaction. It reaches unreachable.
585576
_ = linux.sigaction(@intCast(sig), &new_act, &old_act);
586577
if (old_act.handler.handler == linux.SIG.IGN) {
587578
_ = linux.sigaction(@intCast(sig), &old_act, null);

0 commit comments

Comments
 (0)