signal: correct sigset() return value & errno

ref:
https://man7.org/linux/man-pages/man3/sigset.3.html
The dispositions for SIGKILL and SIGSTOP cannot be changed.

Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
ligd 2022-11-28 11:32:00 +08:00 committed by Xiang Xiao
parent af2b491420
commit eef619fc46
1 changed files with 18 additions and 4 deletions

View File

@ -26,6 +26,7 @@
#include <signal.h>
#include <assert.h>
#include <errno.h>
/****************************************************************************
* Public Functions
@ -98,9 +99,14 @@ _sa_handler_t sigset(int signo, _sa_handler_t func)
{
_sa_handler_t disposition;
sigset_t set;
int ret;
int ret = -EINVAL;
DEBUGASSERT(GOOD_SIGNO(signo) && func != SIG_ERR);
if (signo == SIGKILL || signo == SIGSTOP || !GOOD_SIGNO(signo))
{
goto err;
}
DEBUGASSERT(func != SIG_ERR);
sigemptyset(&set);
sigaddset(&set, signo);
@ -110,7 +116,12 @@ _sa_handler_t sigset(int signo, _sa_handler_t func)
if (func == SIG_HOLD)
{
ret = sigprocmask(SIG_BLOCK, &set, NULL);
disposition = ret < 0 ? SIG_ERR : SIG_HOLD;
if (ret < 0)
{
goto err;
}
disposition = SIG_HOLD;
}
/* No.. then signal can handle the other cases */
@ -132,10 +143,13 @@ _sa_handler_t sigset(int signo, _sa_handler_t func)
*/
signal(signo, disposition);
disposition = SIG_ERR;
goto err;
}
}
}
return disposition;
err:
set_errno(-ret);
return (_sa_handler_t)SIG_ERR;
}