From 73da1e80f4c7ca102f17bb2cab9e444a1e8a1303 Mon Sep 17 00:00:00 2001 From: Yong Cong Sin Date: Tue, 26 Dec 2023 18:31:52 +0800 Subject: [PATCH] posix: signal: implement `sigprocmask()` Implement `sigprocmask()` by simply redirecting call to the `pthread_sigmask()` as they are identical. Signed-off-by: Yong Cong Sin --- include/zephyr/posix/signal.h | 1 + lib/posix/signal.c | 18 ++++++++++++++++++ tests/posix/headers/src/signal_h.c | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/zephyr/posix/signal.h b/include/zephyr/posix/signal.h index 327ca20edc..d22ac34c48 100644 --- a/include/zephyr/posix/signal.h +++ b/include/zephyr/posix/signal.h @@ -99,6 +99,7 @@ int sigfillset(sigset_t *set); int sigaddset(sigset_t *set, int signo); int sigdelset(sigset_t *set, int signo); int sigismember(const sigset_t *set, int signo); +int sigprocmask(int how, const sigset_t *ZRESTRICT set, sigset_t *ZRESTRICT oset); int pthread_sigmask(int how, const sigset_t *ZRESTRICT set, sigset_t *ZRESTRICT oset); #endif /* CONFIG_POSIX_SIGNAL */ diff --git a/lib/posix/signal.c b/lib/posix/signal.c index d2153238ff..f14ef7fe61 100644 --- a/lib/posix/signal.c +++ b/lib/posix/signal.c @@ -100,3 +100,21 @@ char *strsignal(int signum) return buf; } + +int sigprocmask(int how, const sigset_t *ZRESTRICT set, sigset_t *ZRESTRICT oset) +{ + if (!IS_ENABLED(CONFIG_MULTITHREADING)) { + return pthread_sigmask(how, set, oset); + } + + /* + * Until Zephyr supports processes and specifically querying the number of active threads in + * a process For more information, see + * https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_sigmask.html + */ + __ASSERT(false, "In multi-threaded environments, please use pthread_sigmask() instead of " + "%s()", __func__); + + errno = ENOSYS; + return -1; +} diff --git a/tests/posix/headers/src/signal_h.c b/tests/posix/headers/src/signal_h.c index 58c17dd623..9d0be5778d 100644 --- a/tests/posix/headers/src/signal_h.c +++ b/tests/posix/headers/src/signal_h.c @@ -164,6 +164,7 @@ ZTEST(posix_headers, test_signal_h) zassert_not_null(sigdelset); zassert_not_null(sigismember); zassert_not_null(strsignal); + zassert_not_null(sigprocmask); zassert_not_null(pthread_sigmask); #endif /* CONFIG_POSIX_SIGNAL */ @@ -182,7 +183,6 @@ ZTEST(posix_headers, test_signal_h) /* zassert_not_null(signal); */ /* not implemented */ /* zassert_not_null(sigpause); */ /* not implemented */ /* zassert_not_null(sigpending); */ /* not implemented */ - /* zassert_not_null(sigprocmask); */ /* not implemented */ /* zassert_not_null(sigqueue); */ /* not implemented */ /* zassert_not_null(sigrelse); */ /* not implemented */ /* zassert_not_null(sigset); */ /* not implemented */