| author | |
| committer | |
| log | 2cced8903e07066a724a81257dadae233dd5893f |
| tree | b362b1feea40b538fde6cf2ee503125107414415 |
| parent | 4d2868f24298981f67dea03ab523a97fd9399a43 |
| signature |
The set of signals that cannot have their action changed is documented in POSIX,
and any additional, non-standard signals are documented by the specific OS. I
see no valid reason why EINVAL should be considered an unpredictable error here.6 files changed, 22 insertions(+), 29 deletions(-)
lib/std/Progress.zig+1-3| ... | ... | @@ -414,9 +414,7 @@ pub fn start(options: Options) Node { |
| 414 | 414 | .mask = posix.empty_sigset, |
| 415 | 415 | .flags = (posix.SA.SIGINFO | posix.SA.RESTART), |
| 416 | 416 | }; |
| 417 | posix.sigaction(posix.SIG.WINCH, &act, null) catch |err| { | |
| 418 | std.log.warn("failed to install SIGWINCH signal handler for noticing terminal resizes: {s}", .{@errorName(err)}); | |
| 419 | }; | |
| 417 | posix.sigaction(posix.SIG.WINCH, &act, null); | |
| 420 | 418 | } |
| 421 | 419 | |
| 422 | 420 | if (switch (global_progress.terminal_mode) { |
lib/std/debug.zig+7-10| ... | ... | @@ -2601,11 +2601,11 @@ pub fn maybeEnableSegfaultHandler() void { |
| 2601 | 2601 | |
| 2602 | 2602 | var windows_segfault_handle: ?windows.HANDLE = null; |
| 2603 | 2603 | |
| 2604 | pub fn updateSegfaultHandler(act: ?*const posix.Sigaction) error{OperationNotSupported}!void { | |
| 2605 | try posix.sigaction(posix.SIG.SEGV, act, null); | |
| 2606 | try posix.sigaction(posix.SIG.ILL, act, null); | |
| 2607 | try posix.sigaction(posix.SIG.BUS, act, null); | |
| 2608 | try posix.sigaction(posix.SIG.FPE, act, null); | |
| 2604 | pub fn updateSegfaultHandler(act: ?*const posix.Sigaction) void { | |
| 2605 | posix.sigaction(posix.SIG.SEGV, act, null); | |
| 2606 | posix.sigaction(posix.SIG.ILL, act, null); | |
| 2607 | posix.sigaction(posix.SIG.BUS, act, null); | |
| 2608 | posix.sigaction(posix.SIG.FPE, act, null); | |
| 2609 | 2609 | } |
| 2610 | 2610 | |
| 2611 | 2611 | /// Attaches a global SIGSEGV handler which calls `@panic("segmentation fault");` |
| ... | ... | @@ -2623,9 +2623,7 @@ pub fn attachSegfaultHandler() void { |
| 2623 | 2623 | .flags = (posix.SA.SIGINFO | posix.SA.RESTART | posix.SA.RESETHAND), |
| 2624 | 2624 | }; |
| 2625 | 2625 | |
| 2626 | updateSegfaultHandler(&act) catch { | |
| 2627 | @panic("unable to install segfault handler, maybe adjust have_segfault_handling_support in std/debug.zig"); | |
| 2628 | }; | |
| 2626 | updateSegfaultHandler(&act); | |
| 2629 | 2627 | } |
| 2630 | 2628 | |
| 2631 | 2629 | fn resetSegfaultHandler() void { |
| ... | ... | @@ -2641,8 +2639,7 @@ fn resetSegfaultHandler() void { |
| 2641 | 2639 | .mask = posix.empty_sigset, |
| 2642 | 2640 | .flags = 0, |
| 2643 | 2641 | }; |
| 2644 | // To avoid a double-panic, do nothing if an error happens here. | |
| 2645 | updateSegfaultHandler(&act) catch {}; | |
| 2642 | updateSegfaultHandler(&act); | |
| 2646 | 2643 | } |
| 2647 | 2644 | |
| 2648 | 2645 | fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.C) noreturn { |
lib/std/posix.zig+6-5| ... | ... | @@ -683,9 +683,7 @@ pub fn abort() noreturn { |
| 683 | 683 | .mask = empty_sigset, |
| 684 | 684 | .flags = 0, |
| 685 | 685 | }; |
| 686 | sigaction(SIG.ABRT, &sigact, null) catch |err| switch (err) { | |
| 687 | error.OperationNotSupported => unreachable, | |
| 688 | }; | |
| 686 | sigaction(SIG.ABRT, &sigact, null); | |
| 689 | 687 | |
| 690 | 688 | _ = linux.tkill(linux.gettid(), SIG.ABRT); |
| 691 | 689 | |
| ... | ... | @@ -5658,10 +5656,13 @@ pub fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) SigaltstackError!void { |
| 5658 | 5656 | } |
| 5659 | 5657 | |
| 5660 | 5658 | /// Examine and change a signal action. |
| 5661 | pub fn sigaction(sig: u6, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) error{OperationNotSupported}!void { | |
| 5659 | pub fn sigaction(sig: u6, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) void { | |
| 5662 | 5660 | switch (errno(system.sigaction(sig, act, oact))) { |
| 5663 | 5661 | .SUCCESS => return, |
| 5664 | .INVAL => return error.OperationNotSupported, | |
| 5662 | // EINVAL means the signal is either invalid or some signal that cannot have its action | |
| 5663 | // changed. For POSIX, this means SIGKILL/SIGSTOP. For e.g. Solaris, this also includes the | |
| 5664 | // non-standard SIGWAITING, SIGCANCEL, and SIGLWP. Either way, programmer error. | |
| 5665 | .INVAL => unreachable, | |
| 5665 | 5666 | else => unreachable, |
| 5666 | 5667 | } |
| 5667 | 5668 | } |
lib/std/posix/test.zig+6-6| ... | ... | @@ -862,10 +862,10 @@ test "sigaction" { |
| 862 | 862 | var old_sa: posix.Sigaction = undefined; |
| 863 | 863 | |
| 864 | 864 | // Install the new signal handler. |
| 865 | try posix.sigaction(posix.SIG.USR1, &sa, null); | |
| 865 | posix.sigaction(posix.SIG.USR1, &sa, null); | |
| 866 | 866 | |
| 867 | 867 | // Check that we can read it back correctly. |
| 868 | try posix.sigaction(posix.SIG.USR1, null, &old_sa); | |
| 868 | posix.sigaction(posix.SIG.USR1, null, &old_sa); | |
| 869 | 869 | try testing.expectEqual(&S.handler, old_sa.handler.sigaction.?); |
| 870 | 870 | try testing.expect((old_sa.flags & posix.SA.SIGINFO) != 0); |
| 871 | 871 | |
| ... | ... | @@ -874,26 +874,26 @@ test "sigaction" { |
| 874 | 874 | try testing.expect(S.handler_called_count == 1); |
| 875 | 875 | |
| 876 | 876 | // Check if passing RESETHAND correctly reset the handler to SIG_DFL |
| 877 | try posix.sigaction(posix.SIG.USR1, null, &old_sa); | |
| 877 | posix.sigaction(posix.SIG.USR1, null, &old_sa); | |
| 878 | 878 | try testing.expectEqual(posix.SIG.DFL, old_sa.handler.handler); |
| 879 | 879 | |
| 880 | 880 | // Reinstall the signal w/o RESETHAND and re-raise |
| 881 | 881 | sa.flags = posix.SA.SIGINFO; |
| 882 | try posix.sigaction(posix.SIG.USR1, &sa, null); | |
| 882 | posix.sigaction(posix.SIG.USR1, &sa, null); | |
| 883 | 883 | try posix.raise(posix.SIG.USR1); |
| 884 | 884 | try testing.expect(S.handler_called_count == 2); |
| 885 | 885 | |
| 886 | 886 | // Now set the signal to ignored |
| 887 | 887 | sa.handler = .{ .handler = posix.SIG.IGN }; |
| 888 | 888 | sa.flags = 0; |
| 889 | try posix.sigaction(posix.SIG.USR1, &sa, null); | |
| 889 | posix.sigaction(posix.SIG.USR1, &sa, null); | |
| 890 | 890 | |
| 891 | 891 | // Re-raise to ensure handler is actually ignored |
| 892 | 892 | try posix.raise(posix.SIG.USR1); |
| 893 | 893 | try testing.expect(S.handler_called_count == 2); |
| 894 | 894 | |
| 895 | 895 | // Ensure that ignored state is returned when querying |
| 896 | try posix.sigaction(posix.SIG.USR1, null, &old_sa); | |
| 896 | posix.sigaction(posix.SIG.USR1, null, &old_sa); | |
| 897 | 897 | try testing.expectEqual(posix.SIG.IGN, old_sa.handler.handler.?); |
| 898 | 898 | } |
| 899 | 899 |
lib/std/start.zig+1-2| ... | ... | @@ -609,8 +609,7 @@ fn maybeIgnoreSigpipe() void { |
| 609 | 609 | .mask = posix.empty_sigset, |
| 610 | 610 | .flags = 0, |
| 611 | 611 | }; |
| 612 | posix.sigaction(posix.SIG.PIPE, &act, null) catch |err| | |
| 613 | std.debug.panic("failed to set noop SIGPIPE handler: {s}", .{@errorName(err)}); | |
| 612 | posix.sigaction(posix.SIG.PIPE, &act, null); | |
| 614 | 613 | } |
| 615 | 614 | } |
| 616 | 615 |
src/crash_report.zig+1-3| ... | ... | @@ -163,9 +163,7 @@ pub fn attachSegfaultHandler() void { |
| 163 | 163 | .flags = (posix.SA.SIGINFO | posix.SA.RESTART | posix.SA.RESETHAND), |
| 164 | 164 | }; |
| 165 | 165 | |
| 166 | debug.updateSegfaultHandler(&act) catch { | |
| 167 | @panic("unable to install segfault handler, maybe adjust have_segfault_handling_support in std/debug.zig"); | |
| 168 | }; | |
| 166 | debug.updateSegfaultHandler(&act); | |
| 169 | 167 | } |
| 170 | 168 | |
| 171 | 169 | fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.C) noreturn { |