From 235013eb5537fda09d0d291a941de9da1d382d62 Mon Sep 17 00:00:00 2001 From: claudio Date: Mon, 29 Jul 2024 12:42:53 +0000 Subject: [PATCH] Move the signal related kqueue filters to kern_event.c. Since proc and signal filters share the same klist it makes sense to keep them together. OK mvs@ --- sys/kern/kern_event.c | 61 +++++++++++++++++++++++++++++++++++++++++- sys/kern/kern_sig.c | 62 +------------------------------------------ sys/sys/event.h | 3 +-- 3 files changed, 62 insertions(+), 64 deletions(-) diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c index 7e3ae6eae3a..e2c99fe1e78 100644 --- a/sys/kern/kern_event.c +++ b/sys/kern/kern_event.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_event.c,v 1.198 2023/08/20 15:13:43 visa Exp $ */ +/* $OpenBSD: kern_event.c,v 1.199 2024/07/29 12:42:53 claudio Exp $ */ /*- * Copyright (c) 1999,2000,2001 Jonathan Lemon @@ -124,6 +124,9 @@ int filt_kqueue_common(struct knote *kn, struct kqueue *kq); int filt_procattach(struct knote *kn); void filt_procdetach(struct knote *kn); int filt_proc(struct knote *kn, long hint); +int filt_sigattach(struct knote *kn); +void filt_sigdetach(struct knote *kn); +int filt_signal(struct knote *kn, long hint); int filt_fileattach(struct knote *kn); void filt_timerexpire(void *knx); int filt_timerattach(struct knote *kn); @@ -148,6 +151,13 @@ const struct filterops proc_filtops = { .f_event = filt_proc, }; +const struct filterops sig_filtops = { + .f_flags = 0, + .f_attach = filt_sigattach, + .f_detach = filt_sigdetach, + .f_event = filt_signal, +}; + const struct filterops file_filtops = { .f_flags = FILTEROP_ISFD | FILTEROP_MPSAFE, .f_attach = filt_fileattach, @@ -450,6 +460,55 @@ filt_proc(struct knote *kn, long hint) return (kn->kn_fflags != 0); } +/* + * signal knotes are shared with proc knotes, so we apply a mask to + * the hint in order to differentiate them from process hints. This + * could be avoided by using a signal-specific knote list, but probably + * isn't worth the trouble. + */ +int +filt_sigattach(struct knote *kn) +{ + struct process *pr = curproc->p_p; + int s; + + if (kn->kn_id >= NSIG) + return EINVAL; + + kn->kn_ptr.p_process = pr; + kn->kn_flags |= EV_CLEAR; /* automatically set */ + + s = splhigh(); + klist_insert_locked(&pr->ps_klist, kn); + splx(s); + + return (0); +} + +void +filt_sigdetach(struct knote *kn) +{ + struct process *pr = kn->kn_ptr.p_process; + int s; + + s = splhigh(); + klist_remove_locked(&pr->ps_klist, kn); + splx(s); +} + +int +filt_signal(struct knote *kn, long hint) +{ + + if (hint & NOTE_SIGNAL) { + hint &= ~NOTE_SIGNAL; + + if (kn->kn_id == hint) + kn->kn_data++; + } + return (kn->kn_data != 0); +} + #define NOTE_TIMER_UNITMASK \ (NOTE_SECONDS|NOTE_MSECONDS|NOTE_USECONDS|NOTE_NSECONDS) diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index dd54c552edc..2eafc58109e 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sig.c,v 1.335 2024/07/29 09:49:49 claudio Exp $ */ +/* $OpenBSD: kern_sig.c,v 1.336 2024/07/29 12:42:53 claudio Exp $ */ /* $NetBSD: kern_sig.c,v 1.54 1996/04/22 01:38:32 christos Exp $ */ /* @@ -70,17 +70,6 @@ int nosuidcoredump = 1; -int filt_sigattach(struct knote *kn); -void filt_sigdetach(struct knote *kn); -int filt_signal(struct knote *kn, long hint); - -const struct filterops sig_filtops = { - .f_flags = 0, - .f_attach = filt_sigattach, - .f_detach = filt_sigdetach, - .f_event = filt_signal, -}; - /* * The array below categorizes the signals and their default actions. */ @@ -1974,55 +1963,6 @@ initsiginfo(siginfo_t *si, int sig, u_long trapno, int code, union sigval val) } } -int -filt_sigattach(struct knote *kn) -{ - struct process *pr = curproc->p_p; - int s; - - if (kn->kn_id >= NSIG) - return EINVAL; - - kn->kn_ptr.p_process = pr; - kn->kn_flags |= EV_CLEAR; /* automatically set */ - - s = splhigh(); - klist_insert_locked(&pr->ps_klist, kn); - splx(s); - - return (0); -} - -void -filt_sigdetach(struct knote *kn) -{ - struct process *pr = kn->kn_ptr.p_process; - int s; - - s = splhigh(); - klist_remove_locked(&pr->ps_klist, kn); - splx(s); -} - -/* - * signal knotes are shared with proc knotes, so we apply a mask to - * the hint in order to differentiate them from process hints. This - * could be avoided by using a signal-specific knote list, but probably - * isn't worth the trouble. - */ -int -filt_signal(struct knote *kn, long hint) -{ - - if (hint & NOTE_SIGNAL) { - hint &= ~NOTE_SIGNAL; - - if (kn->kn_id == hint) - kn->kn_data++; - } - return (kn->kn_data != 0); -} - void userret(struct proc *p) { diff --git a/sys/sys/event.h b/sys/sys/event.h index 6d052d23b4b..20cca20bcad 100644 --- a/sys/sys/event.h +++ b/sys/sys/event.h @@ -1,4 +1,4 @@ -/* $OpenBSD: event.h,v 1.71 2023/08/20 15:13:43 visa Exp $ */ +/* $OpenBSD: event.h,v 1.72 2024/07/29 12:42:53 claudio Exp $ */ /*- * Copyright (c) 1999,2000,2001 Jonathan Lemon @@ -285,7 +285,6 @@ struct proc; struct rwlock; struct timespec; -extern const struct filterops sig_filtops; extern const struct filterops dead_filtops; extern void kqpoll_init(unsigned int); -- 2.20.1