git: 02a2aacbe2c8 - main - issignal(): ignore signals when process is single-threading for exit
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 13 Jun 2022 19:33:29 UTC
The branch main has been updated by kib:
URL: https://cgit.FreeBSD.org/src/commit/?id=02a2aacbe2c81be455811fa9d4200101f70a86d2
commit 02a2aacbe2c81be455811fa9d4200101f70a86d2
Author: Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2022-05-26 19:18:57 +0000
Commit: Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-06-13 19:30:02 +0000
issignal(): ignore signals when process is single-threading for exit
Places that will wait for curproc->p_singlethr to become zero (in the
next commit, the counter of number of external single-threading is
to be introduced), must wait for it interruptible, otherwise we
deadlock. On the other hand, a signal delivered during this window,
if directed to the waiting thread, would cause the wait loop to become
a busy loop.
Since we are exiting, it is safe to ignore the signals.
Reviewed by: markj
Tested by: pho
Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Differential revision: https://reviews.freebsd.org/D35310
---
sys/kern/kern_sig.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c
index afb2fd78c231..e3bbbd23ae6c 100644
--- a/sys/kern/kern_sig.c
+++ b/sys/kern/kern_sig.c
@@ -2928,7 +2928,7 @@ sigprocess(struct thread *td, int sig)
/*
* We should allow pending but ignored signals below
- * only if there is sigwait() active, or P_TRACED was
+ * if there is sigwait() active, or P_TRACED was
* on when they were posted.
*/
if (SIGISMEMBER(ps->ps_sigignore, sig) &&
@@ -2937,6 +2937,16 @@ sigprocess(struct thread *td, int sig)
return (SIGSTATUS_IGNORE);
}
+ /*
+ * If the process is going to single-thread mode to prepare
+ * for exit, there is no sense in delivering any signal
+ * to usermode. Another important consequence is that
+ * msleep(..., PCATCH, ...) now is only interruptible by a
+ * suspend request.
+ */
+ if ((p->p_flag2 & P2_WEXIT) != 0)
+ return (SIGSTATUS_IGNORE);
+
if ((p->p_flag & (P_TRACED | P_PPTRACE)) == P_TRACED) {
/*
* If traced, always stop.