| ... | ... | @@ -739,8 +739,6 @@ test "shutdown socket" { |
| 739 | 739 | os.closeSocket(sock); |
| 740 | 740 | } |
| 741 | 741 | |
| 742 | | var signal_test_handler_called_count: u32 = 0; |
| 743 | | |
| 744 | 742 | test "sigaction" { |
| 745 | 743 | if (native_os == .wasi or native_os == .windows) |
| 746 | 744 | return error.SkipZigTest; |
| ... | ... | @@ -750,17 +748,19 @@ test "sigaction" { |
| 750 | 748 | return error.SkipZigTest; |
| 751 | 749 | |
| 752 | 750 | const S = struct { |
| 751 | var handler_called_count: u32 = 0; |
| 752 | |
| 753 | 753 | fn handler(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const anyopaque) callconv(.C) void { |
| 754 | 754 | _ = ctx_ptr; |
| 755 | 755 | // Check that we received the correct signal. |
| 756 | 756 | switch (native_os) { |
| 757 | 757 | .netbsd => { |
| 758 | 758 | if (sig == os.SIG.USR1 and sig == info.info.signo) |
| 759 | | signal_test_handler_called_count += 1; |
| 759 | handler_called_count += 1; |
| 760 | 760 | }, |
| 761 | 761 | else => { |
| 762 | 762 | if (sig == os.SIG.USR1 and sig == info.signo) |
| 763 | | signal_test_handler_called_count += 1; |
| 763 | handler_called_count += 1; |
| 764 | 764 | }, |
| 765 | 765 | } |
| 766 | 766 | } |
| ... | ... | @@ -774,25 +774,39 @@ test "sigaction" { |
| 774 | 774 | .flags = os.SA.SIGINFO | os.SA.RESETHAND, |
| 775 | 775 | }; |
| 776 | 776 | var old_sa: os.Sigaction = undefined; |
| 777 | |
| 777 | 778 | // Install the new signal handler. |
| 778 | 779 | try os.sigaction(os.SIG.USR1, &sa, null); |
| 780 | |
| 779 | 781 | // Check that we can read it back correctly. |
| 780 | 782 | try os.sigaction(os.SIG.USR1, null, &old_sa); |
| 781 | 783 | try testing.expectEqual(actual_handler, old_sa.handler.sigaction.?); |
| 782 | 784 | try testing.expect((old_sa.flags & os.SA.SIGINFO) != 0); |
| 785 | |
| 783 | 786 | // Invoke the handler. |
| 784 | 787 | try os.raise(os.SIG.USR1); |
| 785 | | try testing.expect(signal_test_handler_called_count == 1); |
| 786 | | // Check if the handler has been correctly reset to SIG_DFL |
| 788 | try testing.expect(S.handler_called_count == 1); |
| 789 | |
| 790 | // Check if passing RESETHAND correctly reset the handler to SIG_DFL |
| 787 | 791 | try os.sigaction(os.SIG.USR1, null, &old_sa); |
| 788 | 792 | try testing.expectEqual(os.SIG.DFL, old_sa.handler.handler); |
| 789 | | // ensure we can ignore a signal |
| 793 | |
| 794 | // Reinstall the signal w/o RESETHAND and re-raise |
| 795 | sa.flags = os.SA.SIGINFO; |
| 796 | try os.sigaction(os.SIG.USR1, &sa, null); |
| 797 | try os.raise(os.SIG.USR1); |
| 798 | try testing.expect(S.handler_called_count == 2); |
| 799 | |
| 800 | // Now set the signal to ignored |
| 790 | 801 | sa.handler = .{ .handler = os.SIG.IGN }; |
| 802 | sa.flags = 0; |
| 791 | 803 | try os.sigaction(os.SIG.USR1, &sa, null); |
| 792 | | // and ensure it is now ignored |
| 804 | |
| 805 | // Re-raise to ensure handler is actually ignored |
| 793 | 806 | try os.raise(os.SIG.USR1); |
| 794 | | try testing.expect(signal_test_handler_called_count == 1); |
| 795 | | // and that ignored state is returned when querying |
| 807 | try testing.expect(S.handler_called_count == 2); |
| 808 | |
| 809 | // Ensure that ignored state is returned when querying |
| 796 | 810 | try os.sigaction(os.SIG.USR1, null, &old_sa); |
| 797 | 811 | try testing.expectEqual(os.SIG.IGN, old_sa.handler.handler.?); |
| 798 | 812 | } |