-
Notifications
You must be signed in to change notification settings - Fork 7.4k
posix: signal: implement sigprocmask()
#67008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Just want to understand well that part : /* this should probably go into signal.c but we need access to the lock */
int pthread_sigmask(int how, const sigset_t *ZRESTRICT set, sigset_t *ZRESTRICT oset)
{
struct posix_thread *t;
if (!(how == SIG_BLOCK || how == SIG_SETMASK || how == SIG_UNBLOCK)) {
return EINVAL;
}
t = to_posix_thread(pthread_self());
if (t == NULL) {
return ESRCH;
}
K_SPINLOCK(&pthread_pool_lock) {
if (oset != NULL) {
*oset = t->sigset;
}
if (set == NULL) {
K_SPINLOCK_BREAK;
}
switch (how) {
case SIG_BLOCK:
for (size_t i = 0; i < ARRAY_SIZE(set->sig); ++i) {
t->sigset.sig[i] |= set->sig[i];
}
break;
case SIG_SETMASK:
t->sigset = *set;
break;
case SIG_UNBLOCK:
for (size_t i = 0; i < ARRAY_SIZE(set->sig); ++i) {
t->sigset.sig[i] &= ~set->sig[i];
}
break;
}
}
return 0;
} Could we move the nonlock part on the signal file and apply the block part from thread fonction ? /* this should probably go into signal.c but we need access to the lock */
int sigmask(int how, const sigset_t *ZRESTRICT set, sigset_t *ZRESTRICT oset)
{
struct posix_thread *t;
if (!(how == SIG_BLOCK || how == SIG_SETMASK || how == SIG_UNBLOCK)) {
return EINVAL;
}
t = to_posix_thread(pthread_self());
if (t == NULL) {
return ESRCH;
}
pthread_lockPartFunction(struct posix_thread *t,int how, const sigset_t *ZRESTRICT set, sigset_t *ZRESTRICT oset);
return 0;
} I want to write it to understand and now I writed it, it sounds so bad 😂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A temporary nak for the moment because sigprocmask()
should only be used with a single-threaded process.
In Zephyr, even with the approximation that we are running in a single process environment, it is (normally) a multi-threaded environment.
This might need to check a Kconfig variable CONFIG_MULTITHREADED
before calling into pthread_sigmask()
.
Likely if CONFIG_MULTITHREADED
is chosen, and this function is called, it might need to assert, since it's "unspecified" according to the spec.
https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigprocmask.html
40aeebe
to
ff7f9e7
Compare
Implement `sigprocmask()` by simply redirecting call to the `pthread_sigmask()` as they are identical. Signed-off-by: Yong Cong Sin <[email protected]>
ff7f9e7
to
2e44777
Compare
Refactor the existing `pthread_sigmask` test function to get its function-under-test via arg and test `sigprocmask` with that. Signed-off-by: Yong Cong Sin <[email protected]>
`sigprocmask()` is now implemented, mark it so. Signed-off-by: Yong Cong Sin <[email protected]>
2e44777
to
695ade0
Compare
The `sigsuspend` is currently `igsuspend`, fix that. Signed-off-by: Yong Cong Sin <[email protected]>
@@ -230,68 +231,67 @@ static void *test_pthread_sigmask_entry(void *arg) | |||
}; | |||
static sigset_t set[2]; | |||
const int invalid_how = 0x9a2ba9e; | |||
|
|||
ARG_UNUSED(arg); | |||
sigmask_fn sigmask = arg; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is cool 👍
Implement
sigprocmask()
by simply redirecting call to thepthread_sigmask()
as they are identical in single threaded application.Fixes #66928