Skip to content

Commit b62cd39

Browse files
committed
posix: remove empty_sigset
When linking a libc, Zig should defer to the C library for sigset operations. The pre-filled constants signal sets (empty_sigset, filled_sigset) are not compatible with C library initialization, so remove them and use the runtime `sigemptyset` and `sigfillset` methods to initialize any sigset.
1 parent e7c0997 commit b62cd39

File tree

7 files changed

+26
-19
lines changed

7 files changed

+26
-19
lines changed

lib/std/Progress.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,10 @@ pub fn start(options: Options) Node {
412412
if (have_sigwinch) {
413413
var act: posix.Sigaction = .{
414414
.handler = .{ .sigaction = handleSigWinch },
415-
.mask = posix.empty_sigset,
415+
.mask = undefined,
416416
.flags = (posix.SA.SIGINFO | posix.SA.RESTART),
417417
};
418+
posix.sigemptyset(&act.mask);
418419
posix.sigaction(posix.SIG.WINCH, &act, null);
419420
}
420421

lib/std/debug.zig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,9 +1387,10 @@ pub fn attachSegfaultHandler() void {
13871387
}
13881388
var act = posix.Sigaction{
13891389
.handler = .{ .sigaction = handleSegfaultPosix },
1390-
.mask = posix.empty_sigset,
1390+
.mask = undefined,
13911391
.flags = (posix.SA.SIGINFO | posix.SA.RESTART | posix.SA.RESETHAND),
13921392
};
1393+
posix.sigemptyset(&act.mask);
13931394

13941395
updateSegfaultHandler(&act);
13951396
}
@@ -1404,9 +1405,10 @@ fn resetSegfaultHandler() void {
14041405
}
14051406
var act = posix.Sigaction{
14061407
.handler = .{ .handler = posix.SIG.DFL },
1407-
.mask = posix.empty_sigset,
1408+
.mask = undefined,
14081409
.flags = 0,
14091410
};
1411+
posix.sigemptyset(&act.mask);
14101412
updateSegfaultHandler(&act);
14111413
}
14121414

lib/std/posix.zig

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ pub const timerfd_clockid_t = system.timerfd_clockid_t;
127127
pub const cpu_set_t = system.cpu_set_t;
128128
pub const dev_t = system.dev_t;
129129
pub const dl_phdr_info = system.dl_phdr_info;
130-
pub const empty_sigset = system.empty_sigset;
131130
pub const fd_t = system.fd_t;
132131
pub const file_obj = system.file_obj;
133132
pub const gid_t = system.gid_t;
@@ -691,14 +690,14 @@ pub fn abort() noreturn {
691690
// Install default handler so that the tkill below will terminate.
692691
const sigact = Sigaction{
693692
.handler = .{ .handler = SIG.DFL },
694-
.mask = empty_sigset,
693+
.mask = linux.empty_sigset,
695694
.flags = 0,
696695
};
697696
sigaction(SIG.ABRT, &sigact, null);
698697

699698
_ = linux.tkill(linux.gettid(), SIG.ABRT);
700699

701-
var sigabrtmask = empty_sigset;
700+
var sigabrtmask = linux.empty_sigset;
702701
sigaddset(&sigabrtmask, SIG.ABRT);
703702
sigprocmask(SIG.UNBLOCK, &sigabrtmask, null);
704703

@@ -5831,7 +5830,7 @@ pub fn sigemptyset(set: *sigset_t) void {
58315830
else => unreachable,
58325831
}
58335832
}
5834-
set.* = system.empty_sigset;
5833+
set.* = mem.zeroes(sigset_t);
58355834
}
58365835

58375836
pub fn sigaddset(set: *sigset_t, sig: u8) void {

lib/std/posix/test.zig

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,8 @@ test "sigset add/del" {
887887
if (native_os == .wasi or native_os == .windows)
888888
return error.SkipZigTest;
889889

890-
var sigset = posix.empty_sigset;
890+
var sigset: posix.sigset_t = undefined;
891+
posix.sigemptyset(&sigset);
891892

892893
// See that none are set, then set each one, see that they're all set, then
893894
// remove them all, and then see that none are set.
@@ -903,7 +904,6 @@ test "sigset add/del" {
903904
if (!reserved_signo(i)) {
904905
try expectEqual(true, posix.sigismember(&sigset, @truncate(i)));
905906
}
906-
try expectEqual(false, posix.sigismember(&posix.empty_sigset, @truncate(i)));
907907
}
908908
for (1..posix.NSIG) |i| {
909909
if (!reserved_signo(i)) {
@@ -944,9 +944,10 @@ test "sigaction" {
944944

945945
var sa: posix.Sigaction = .{
946946
.handler = .{ .sigaction = &S.handler },
947-
.mask = posix.empty_sigset,
947+
.mask = undefined,
948948
.flags = posix.SA.SIGINFO | posix.SA.RESETHAND,
949949
};
950+
posix.sigemptyset(&sa.mask);
950951
var old_sa: posix.Sigaction = undefined;
951952

952953
// Install the new signal handler.
@@ -1019,17 +1020,19 @@ test "sigset_t bits" {
10191020

10201021
var sa: posix.Sigaction = .{
10211022
.handler = .{ .sigaction = &S.handler },
1022-
.mask = posix.empty_sigset,
1023+
.mask = undefined,
10231024
.flags = posix.SA.SIGINFO | posix.SA.RESETHAND,
10241025
};
1026+
posix.sigemptyset(&sa.mask);
10251027
var old_sa: posix.Sigaction = undefined;
10261028

10271029
// Install the new signal handler.
10281030
posix.sigaction(test_signo, &sa, &old_sa);
10291031

10301032
// block the signal and see that its delayed until unblocked
1031-
var block_one = posix.empty_sigset;
1032-
_ = posix.sigaddset(&block_one, test_signo);
1033+
var block_one: posix.sigset_t = undefined;
1034+
posix.sigemptyset(&block_one);
1035+
posix.sigaddset(&block_one, test_signo);
10331036
posix.sigprocmask(posix.SIG.BLOCK, &block_one, null);
10341037

10351038
// qemu maps target signals to host signals 1-to-1, so targets

lib/std/start.zig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,13 +745,14 @@ fn maybeIgnoreSigpipe() void {
745745

746746
if (have_sigpipe_support and !std.options.keep_sigpipe) {
747747
const posix = std.posix;
748-
const act: posix.Sigaction = .{
748+
var act: posix.Sigaction = .{
749749
// Set handler to a noop function instead of `SIG.IGN` to prevent
750750
// leaking signal disposition to a child process.
751751
.handler = .{ .handler = noopSigHandler },
752-
.mask = posix.empty_sigset,
752+
.mask = undefined,
753753
.flags = 0,
754754
};
755+
posix.sigemptyset(&act.mask);
755756
posix.sigaction(posix.SIG.PIPE, &act, null);
756757
}
757758
}

src/crash_report.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@ pub fn attachSegfaultHandler() void {
177177
}
178178
var act: posix.Sigaction = .{
179179
.handler = .{ .sigaction = handleSegfaultPosix },
180-
.mask = posix.empty_sigset,
180+
.mask = undefined,
181181
.flags = (posix.SA.SIGINFO | posix.SA.RESTART | posix.SA.RESETHAND),
182182
};
183-
183+
posix.sigemptyset(&act.mask);
184184
debug.updateSegfaultHandler(&act);
185185
}
186186

test/standalone/sigpipe/build.zig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ pub fn build(b: *std.build.Builder) !void {
1616
// This test runs "breakpipe" as a child process and that process
1717
// depends on inheriting a SIGPIPE disposition of "default".
1818
{
19-
const act = posix.Sigaction{
19+
var act = posix.Sigaction{
2020
.handler = .{ .handler = posix.SIG.DFL },
21-
.mask = posix.empty_sigset,
21+
.mask = undefined,
2222
.flags = 0,
2323
};
24+
posix.sigemptyset(&act.mask);
2425
try posix.sigaction(posix.SIG.PIPE, &act, null);
2526
}
2627

0 commit comments

Comments
 (0)