signal: correct signal() return value & errno
#include <signal.h>
#include <assert.h>
+#include <errno.h>
/****************************************************************************
* 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;
}
