sigqueue(2): add impl-specific flag __SIGQUEUE_TID

(cherry picked from commit 53186bc1435e2c3ccf9c2124c066a08c6a80c504)
This commit is contained in:
Konstantin Belousov 2024-04-19 17:29:05 +03:00
parent de4b8c8ae1
commit ed9e2991c2
2 changed files with 21 additions and 5 deletions

View file

@ -2010,13 +2010,16 @@ sys_sigqueue(struct thread *td, struct sigqueue_args *uap)
}
int
kern_sigqueue(struct thread *td, pid_t pid, int signum, union sigval *value)
kern_sigqueue(struct thread *td, pid_t pid, int signumf, union sigval *value)
{
ksiginfo_t ksi;
struct proc *p;
struct thread *td2;
u_int signum;
int error;
if ((u_int)signum > _SIG_MAXSIG)
signum = signumf & ~__SIGQUEUE_TID;
if (signum > _SIG_MAXSIG)
return (EINVAL);
/*
@ -2026,8 +2029,17 @@ kern_sigqueue(struct thread *td, pid_t pid, int signum, union sigval *value)
if (pid <= 0)
return (EINVAL);
if ((p = pfind_any(pid)) == NULL)
return (ESRCH);
if ((signumf & __SIGQUEUE_TID) == 0) {
if ((p = pfind_any(pid)) == NULL)
return (ESRCH);
td2 = NULL;
} else {
p = td->td_proc;
td2 = tdfind((lwpid_t)pid, p->p_pid);
if (td2 == NULL)
return (ESRCH);
}
error = p_cansignal(td, p, signum);
if (error == 0 && signum != 0) {
ksiginfo_init(&ksi);
@ -2037,7 +2049,7 @@ kern_sigqueue(struct thread *td, pid_t pid, int signum, union sigval *value)
ksi.ksi_pid = td->td_proc->p_pid;
ksi.ksi_uid = td->td_ucred->cr_ruid;
ksi.ksi_value = *value;
error = pksignal(p, ksi.ksi_signo, &ksi);
error = tdsendsignal(p, td2, ksi.ksi_signo, &ksi);
}
PROC_UNLOCK(p);
return (error);

View file

@ -499,6 +499,10 @@ struct sigstack {
#if __BSD_VISIBLE
#define BADSIG SIG_ERR
/* sigqueue(2) signo high-bits flags */
#define __SIGQUEUE_TID 0x80000000 /* queue for tid, instead of pid */
#define __SIGQUEUE_RSRV 0x40000000 /* reserved */
#endif
#if __POSIX_VISIBLE || __XSI_VISIBLE