From 0abd045472a2cf18ee61cbff0164e327ffd25c54 Mon Sep 17 00:00:00 2001 From: davidxu Date: Thu, 16 Aug 2007 05:26:42 +0000 Subject: Add thr_kill2 syscall which sends a signal to a thread in another process. Submitted by: Tijl Coosemans tijl at ulyssis dot org Approved by: re (kensmith) --- sys/kern/kern_thr.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'sys/kern/kern_thr.c') diff --git a/sys/kern/kern_thr.c b/sys/kern/kern_thr.c index bcbe168..de45d0a 100644 --- a/sys/kern/kern_thr.c +++ b/sys/kern/kern_thr.c @@ -53,6 +53,8 @@ __FBSDID("$FreeBSD$"); #include +#include + #ifdef COMPAT_IA32 extern struct sysentvec ia32_freebsd_sysvec; @@ -337,6 +339,59 @@ thr_kill(struct thread *td, struct thr_kill_args *uap) } int +thr_kill2(struct thread *td, struct thr_kill2_args *uap) + /* pid_t pid, long id, int sig */ +{ + struct thread *ttd; + struct proc *p; + int error; + + AUDIT_ARG(signum, uap->sig); + + if (uap->pid == td->td_proc->p_pid) { + p = td->td_proc; + PROC_LOCK(p); + } else if ((p = pfind(uap->pid)) == NULL) { + return (ESRCH); + } + AUDIT_ARG(process, p); + + error = p_cansignal(td, p, uap->sig); + if (error == 0) { + if (uap->id == -1) { + if (uap->sig != 0 && !_SIG_VALID(uap->sig)) { + error = EINVAL; + } else { + error = ESRCH; + FOREACH_THREAD_IN_PROC(p, ttd) { + if (ttd != td) { + error = 0; + if (uap->sig == 0) + break; + tdsignal(p, ttd, uap->sig, NULL); + } + } + } + } else { + if (uap->id != td->td_tid) + ttd = thread_find(p, uap->id); + else + ttd = td; + if (ttd == NULL) + error = ESRCH; + else if (uap->sig == 0) + ; + else if (!_SIG_VALID(uap->sig)) + error = EINVAL; + else + tdsignal(p, ttd, uap->sig, NULL); + } + } + PROC_UNLOCK(p); + return (error); +} + +int thr_suspend(struct thread *td, struct thr_suspend_args *uap) /* const struct timespec *timeout */ { -- cgit v1.1