mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 22:33:08 +00:00
std: fix definition of SIG_IGN, SIG_DFL, etc.
POSIX specifies that the sa_handler field of the sigaction struct may be set to SIG_IGN or SIG_DFL. However, the current constants in the standard library use the function pointer signature corresponding to the sa_sigaction field instead. This may not cause issues in practice because the fields usually occupy the same memory in a union, but this isn't required by POSIX and there may be systems we do not yet support that do this differently. Fixing this also makes the Zig interface less confusing to use after reading the man page.
This commit is contained in:
parent
7d6a7f513b
commit
b78f3bf1f1
@ -814,10 +814,10 @@ pub const sigset_t = u32;
|
|||||||
pub const empty_sigset: sigset_t = 0;
|
pub const empty_sigset: sigset_t = 0;
|
||||||
|
|
||||||
pub const SIG = struct {
|
pub const SIG = struct {
|
||||||
pub const ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize));
|
pub const ERR = @intToPtr(?Sigaction.handler_fn, maxInt(usize));
|
||||||
pub const DFL = @intToPtr(?Sigaction.sigaction_fn, 0);
|
pub const DFL = @intToPtr(?Sigaction.handler_fn, 0);
|
||||||
pub const IGN = @intToPtr(?Sigaction.sigaction_fn, 1);
|
pub const IGN = @intToPtr(?Sigaction.handler_fn, 1);
|
||||||
pub const HOLD = @intToPtr(?Sigaction.sigaction_fn, 5);
|
pub const HOLD = @intToPtr(?Sigaction.handler_fn, 5);
|
||||||
|
|
||||||
/// block specified signal set
|
/// block specified signal set
|
||||||
pub const _BLOCK = 1;
|
pub const _BLOCK = 1;
|
||||||
|
|||||||
@ -609,9 +609,9 @@ pub const S = struct {
|
|||||||
pub const BADSIG = SIG.ERR;
|
pub const BADSIG = SIG.ERR;
|
||||||
|
|
||||||
pub const SIG = struct {
|
pub const SIG = struct {
|
||||||
pub const DFL = @intToPtr(?Sigaction.sigaction_fn, 0);
|
pub const DFL = @intToPtr(?Sigaction.handler_fn, 0);
|
||||||
pub const IGN = @intToPtr(?Sigaction.sigaction_fn, 1);
|
pub const IGN = @intToPtr(?Sigaction.handler_fn, 1);
|
||||||
pub const ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize));
|
pub const ERR = @intToPtr(?Sigaction.handler_fn, maxInt(usize));
|
||||||
|
|
||||||
pub const BLOCK = 1;
|
pub const BLOCK = 1;
|
||||||
pub const UNBLOCK = 2;
|
pub const UNBLOCK = 2;
|
||||||
|
|||||||
@ -670,9 +670,9 @@ pub const SIG = struct {
|
|||||||
pub const UNBLOCK = 2;
|
pub const UNBLOCK = 2;
|
||||||
pub const SETMASK = 3;
|
pub const SETMASK = 3;
|
||||||
|
|
||||||
pub const DFL = @intToPtr(?Sigaction.sigaction_fn, 0);
|
pub const DFL = @intToPtr(?Sigaction.handler_fn, 0);
|
||||||
pub const IGN = @intToPtr(?Sigaction.sigaction_fn, 1);
|
pub const IGN = @intToPtr(?Sigaction.handler_fn, 1);
|
||||||
pub const ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize));
|
pub const ERR = @intToPtr(?Sigaction.handler_fn, maxInt(usize));
|
||||||
|
|
||||||
pub const WORDS = 4;
|
pub const WORDS = 4;
|
||||||
pub const MAXSIG = 128;
|
pub const MAXSIG = 128;
|
||||||
|
|||||||
@ -910,9 +910,9 @@ pub const winsize = extern struct {
|
|||||||
const NSIG = 32;
|
const NSIG = 32;
|
||||||
|
|
||||||
pub const SIG = struct {
|
pub const SIG = struct {
|
||||||
pub const DFL = @intToPtr(?Sigaction.sigaction_fn, 0);
|
pub const DFL = @intToPtr(?Sigaction.handler_fn, 0);
|
||||||
pub const IGN = @intToPtr(?Sigaction.sigaction_fn, 1);
|
pub const IGN = @intToPtr(?Sigaction.handler_fn, 1);
|
||||||
pub const ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize));
|
pub const ERR = @intToPtr(?Sigaction.handler_fn, maxInt(usize));
|
||||||
|
|
||||||
pub const WORDS = 4;
|
pub const WORDS = 4;
|
||||||
pub const MAXSIG = 128;
|
pub const MAXSIG = 128;
|
||||||
|
|||||||
@ -982,11 +982,11 @@ pub const winsize = extern struct {
|
|||||||
const NSIG = 33;
|
const NSIG = 33;
|
||||||
|
|
||||||
pub const SIG = struct {
|
pub const SIG = struct {
|
||||||
pub const DFL = @intToPtr(?Sigaction.sigaction_fn, 0);
|
pub const DFL = @intToPtr(?Sigaction.handler_fn, 0);
|
||||||
pub const IGN = @intToPtr(?Sigaction.sigaction_fn, 1);
|
pub const IGN = @intToPtr(?Sigaction.handler_fn, 1);
|
||||||
pub const ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize));
|
pub const ERR = @intToPtr(?Sigaction.handler_fn, maxInt(usize));
|
||||||
pub const CATCH = @intToPtr(?Sigaction.sigaction_fn, 2);
|
pub const CATCH = @intToPtr(?Sigaction.handler_fn, 2);
|
||||||
pub const HOLD = @intToPtr(?Sigaction.sigaction_fn, 3);
|
pub const HOLD = @intToPtr(?Sigaction.handler_fn, 3);
|
||||||
|
|
||||||
pub const HUP = 1;
|
pub const HUP = 1;
|
||||||
pub const INT = 2;
|
pub const INT = 2;
|
||||||
|
|||||||
@ -879,10 +879,10 @@ pub const winsize = extern struct {
|
|||||||
const NSIG = 75;
|
const NSIG = 75;
|
||||||
|
|
||||||
pub const SIG = struct {
|
pub const SIG = struct {
|
||||||
pub const DFL = @intToPtr(?Sigaction.sigaction_fn, 0);
|
pub const DFL = @intToPtr(?Sigaction.handler_fn, 0);
|
||||||
pub const ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize));
|
pub const ERR = @intToPtr(?Sigaction.handler_fn, maxInt(usize));
|
||||||
pub const IGN = @intToPtr(?Sigaction.sigaction_fn, 1);
|
pub const IGN = @intToPtr(?Sigaction.handler_fn, 1);
|
||||||
pub const HOLD = @intToPtr(?Sigaction.sigaction_fn, 2);
|
pub const HOLD = @intToPtr(?Sigaction.handler_fn, 2);
|
||||||
|
|
||||||
pub const WORDS = 4;
|
pub const WORDS = 4;
|
||||||
pub const MAXSIG = 75;
|
pub const MAXSIG = 75;
|
||||||
|
|||||||
@ -1787,7 +1787,7 @@ fn resetSegfaultHandler() void {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var act = os.Sigaction{
|
var act = os.Sigaction{
|
||||||
.handler = .{ .sigaction = os.SIG.DFL },
|
.handler = .{ .handler = os.SIG.DFL },
|
||||||
.mask = os.empty_sigset,
|
.mask = os.empty_sigset,
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -475,7 +475,7 @@ pub fn abort() noreturn {
|
|||||||
|
|
||||||
// Install default handler so that the tkill below will terminate.
|
// Install default handler so that the tkill below will terminate.
|
||||||
const sigact = Sigaction{
|
const sigact = Sigaction{
|
||||||
.handler = .{ .sigaction = SIG.DFL },
|
.handler = .{ .handler = SIG.DFL },
|
||||||
.mask = empty_sigset,
|
.mask = empty_sigset,
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1945,9 +1945,9 @@ pub const SIG = if (is_mips) struct {
|
|||||||
pub const SYS = 31;
|
pub const SYS = 31;
|
||||||
pub const UNUSED = SIG.SYS;
|
pub const UNUSED = SIG.SYS;
|
||||||
|
|
||||||
pub const ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize));
|
pub const ERR = @intToPtr(?Sigaction.handler_fn, maxInt(usize));
|
||||||
pub const DFL = @intToPtr(?Sigaction.sigaction_fn, 0);
|
pub const DFL = @intToPtr(?Sigaction.handler_fn, 0);
|
||||||
pub const IGN = @intToPtr(?Sigaction.sigaction_fn, 1);
|
pub const IGN = @intToPtr(?Sigaction.handler_fn, 1);
|
||||||
} else if (is_sparc) struct {
|
} else if (is_sparc) struct {
|
||||||
pub const BLOCK = 1;
|
pub const BLOCK = 1;
|
||||||
pub const UNBLOCK = 2;
|
pub const UNBLOCK = 2;
|
||||||
@ -1989,9 +1989,9 @@ pub const SIG = if (is_mips) struct {
|
|||||||
pub const PWR = LOST;
|
pub const PWR = LOST;
|
||||||
pub const IO = SIG.POLL;
|
pub const IO = SIG.POLL;
|
||||||
|
|
||||||
pub const ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize));
|
pub const ERR = @intToPtr(?Sigaction.handler_fn, maxInt(usize));
|
||||||
pub const DFL = @intToPtr(?Sigaction.sigaction_fn, 0);
|
pub const DFL = @intToPtr(?Sigaction.handler_fn, 0);
|
||||||
pub const IGN = @intToPtr(?Sigaction.sigaction_fn, 1);
|
pub const IGN = @intToPtr(?Sigaction.handler_fn, 1);
|
||||||
} else struct {
|
} else struct {
|
||||||
pub const BLOCK = 0;
|
pub const BLOCK = 0;
|
||||||
pub const UNBLOCK = 1;
|
pub const UNBLOCK = 1;
|
||||||
@ -2032,9 +2032,9 @@ pub const SIG = if (is_mips) struct {
|
|||||||
pub const SYS = 31;
|
pub const SYS = 31;
|
||||||
pub const UNUSED = SIG.SYS;
|
pub const UNUSED = SIG.SYS;
|
||||||
|
|
||||||
pub const ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize));
|
pub const ERR = @intToPtr(?Sigaction.handler_fn, maxInt(usize));
|
||||||
pub const DFL = @intToPtr(?Sigaction.sigaction_fn, 0);
|
pub const DFL = @intToPtr(?Sigaction.handler_fn, 0);
|
||||||
pub const IGN = @intToPtr(?Sigaction.sigaction_fn, 1);
|
pub const IGN = @intToPtr(?Sigaction.handler_fn, 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const kernel_rwf = u32;
|
pub const kernel_rwf = u32;
|
||||||
|
|||||||
@ -785,7 +785,7 @@ test "sigaction" {
|
|||||||
try testing.expect(signal_test_failed == false);
|
try testing.expect(signal_test_failed == false);
|
||||||
// Check if the handler has been correctly reset to SIG_DFL
|
// Check if the handler has been correctly reset to SIG_DFL
|
||||||
try os.sigaction(os.SIG.USR1, null, &old_sa);
|
try os.sigaction(os.SIG.USR1, null, &old_sa);
|
||||||
try testing.expectEqual(os.SIG.DFL, old_sa.handler.sigaction);
|
try testing.expectEqual(os.SIG.DFL, old_sa.handler.handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "dup & dup2" {
|
test "dup & dup2" {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user