From 092c78d63654b648010d841576c05763a2ac68a4 Mon Sep 17 00:00:00 2001 From: ligd Date: Fri, 25 Nov 2022 22:59:46 +0800 Subject: [PATCH] signal: correct signal() return value & errno Signed-off-by: ligd --- libs/libc/signal/sig_signal.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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; }