diff --git a/system/lib/libc/sigaction.c b/system/lib/libc/sigaction.c index e76456559a848..080ad45c5a815 100644 --- a/system/lib/libc/sigaction.c +++ b/system/lib/libc/sigaction.c @@ -22,7 +22,10 @@ int __sigaction(int sig, const struct sigaction *restrict sa, struct sigaction * *old = __sig_actions[sig]; } - __sig_actions[sig] = *sa; + if (sa) { + __sig_actions[sig] = *sa; + } + return 0; } diff --git a/tests/test_signals.c b/tests/test_signals.c index 711493215ecb7..10f7839319c5e 100644 --- a/tests/test_signals.c +++ b/tests/test_signals.c @@ -127,7 +127,25 @@ void test_sigwaitinfo() { assert(!recieved1); } +void test_sigaction() { + // Use sigaction to find the existing handlers + struct sigaction action; + sigaction(SIGUSR1, NULL, &action); + assert(action.sa_handler == SIG_DFL); + assert((void (*)(int))action.sa_sigaction == SIG_DFL); + + // Now install a new handler + action.sa_handler = handler1; + sigaction(SIGUSR1, &action, NULL); + + // Verify that the new handler is returned + struct sigaction action2; + sigaction(SIGUSR1, NULL, &action2); + assert(action2.sa_handler == handler1); +} + int main() { + test_sigaction(); test_bad_signal(); test_raise_sigusr1(); test_sigpenging();