diff --git a/libs/libc/signal/sig_signal.c b/libs/libc/signal/sig_signal.c index 506c070234..5dbcf9faae 100644 --- a/libs/libc/signal/sig_signal.c +++ b/libs/libc/signal/sig_signal.c @@ -26,6 +26,7 @@ #include #include +#include /**************************************************************************** * Public Functions @@ -59,9 +60,14 @@ _sa_handler_t signal(int signo, _sa_handler_t func) { struct sigaction act; struct sigaction oact; - int ret; + int ret = -EINVAL; - DEBUGASSERT(GOOD_SIGNO(signo) && func != SIG_ERR && func != SIG_HOLD); + if (!GOOD_SIGNO(signo)) + { + goto err; + } + + DEBUGASSERT(func != SIG_ERR && func != SIG_HOLD); /* Initialize the sigaction structure */ @@ -86,7 +92,7 @@ _sa_handler_t signal(int signo, _sa_handler_t func) { /* Would happen if signo were invalid */ - return (_sa_handler_t)SIG_ERR; + goto err; } } @@ -104,5 +110,7 @@ _sa_handler_t signal(int signo, _sa_handler_t func) return oact.sa_handler; } +err: + set_errno(-ret); return (_sa_handler_t)SIG_ERR; }