From 2e3e423b4d3d62fec3525c2e09fc9daf35fbe885 Mon Sep 17 00:00:00 2001 From: Daniel Fahlgren Date: Wed, 5 Feb 2020 13:24:43 +0100 Subject: [PATCH] Add pthread_sigqueue This makes it possible to queue a signal and data to a thread --- include/signal.h | 1 + src/thread/pthread_sigqueue.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/thread/pthread_sigqueue.c diff --git a/include/signal.h b/include/signal.h index fbdf667b..8bb7d1b4 100644 --- a/include/signal.h +++ b/include/signal.h @@ -214,6 +214,7 @@ int sigqueue(pid_t, int, union sigval); int pthread_sigmask(int, const sigset_t *__restrict, sigset_t *__restrict); int pthread_kill(pthread_t, int); +int pthread_sigqueue(pthread_t, int, union sigval); void psiginfo(const siginfo_t *, const char *); void psignal(int, const char *); diff --git a/src/thread/pthread_sigqueue.c b/src/thread/pthread_sigqueue.c new file mode 100644 index 00000000..8de8d49a --- /dev/null +++ b/src/thread/pthread_sigqueue.c @@ -0,0 +1,23 @@ +#include +#include +#include +#include "pthread_impl.h" +#include "lock.h" + +int pthread_sigqueue(pthread_t t, int sig, const union sigval value) +{ + siginfo_t si; + sigset_t set; + int r; + memset(&si, 0, sizeof si); + si.si_signo = sig; + si.si_code = SI_QUEUE; + si.si_value = value; + si.si_uid = getuid(); + si.si_pid = getpid(); + LOCK(t->killlock); + r = t->tid ? -__syscall(SYS_rt_tgsigqueueinfo, si.si_pid, t->tid, sig, &si) + : (sig+0U >= _NSIG ? EINVAL : 0); + UNLOCK(t->killlock); + return r; +} -- 2.17.1