Skip to content

Commit eef619f

Browse files
GUIDINGLIxiaoxiang781216
authored andcommitted
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 <[email protected]>
1 parent af2b491 commit eef619f

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

libs/libc/signal/sig_set.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include <signal.h>
2828
#include <assert.h>
29+
#include <errno.h>
2930

3031
/****************************************************************************
3132
* Public Functions
@@ -98,9 +99,14 @@ _sa_handler_t sigset(int signo, _sa_handler_t func)
9899
{
99100
_sa_handler_t disposition;
100101
sigset_t set;
101-
int ret;
102+
int ret = -EINVAL;
102103

103-
DEBUGASSERT(GOOD_SIGNO(signo) && func != SIG_ERR);
104+
if (signo == SIGKILL || signo == SIGSTOP || !GOOD_SIGNO(signo))
105+
{
106+
goto err;
107+
}
108+
109+
DEBUGASSERT(func != SIG_ERR);
104110

105111
sigemptyset(&set);
106112
sigaddset(&set, signo);
@@ -110,7 +116,12 @@ _sa_handler_t sigset(int signo, _sa_handler_t func)
110116
if (func == SIG_HOLD)
111117
{
112118
ret = sigprocmask(SIG_BLOCK, &set, NULL);
113-
disposition = ret < 0 ? SIG_ERR : SIG_HOLD;
119+
if (ret < 0)
120+
{
121+
goto err;
122+
}
123+
124+
disposition = SIG_HOLD;
114125
}
115126

116127
/* No.. then signal can handle the other cases */
@@ -132,10 +143,13 @@ _sa_handler_t sigset(int signo, _sa_handler_t func)
132143
*/
133144

134145
signal(signo, disposition);
135-
disposition = SIG_ERR;
146+
goto err;
136147
}
137148
}
138149
}
139150

140151
return disposition;
152+
err:
153+
set_errno(-ret);
154+
return (_sa_handler_t)SIG_ERR;
141155
}

0 commit comments

Comments
 (0)