git: a6caa7bc5423 - stable/13 - stop_all_proc(): skip traced or signal-stoped processes

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Wed, 17 Apr 2024 08:13:38 UTC
The branch stable/13 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=a6caa7bc54235cdc1599038fe4164015c2931545

commit a6caa7bc54235cdc1599038fe4164015c2931545
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-04-04 19:24:32 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-04-17 08:13:17 +0000

    stop_all_proc(): skip traced or signal-stoped processes
    
    (cherry picked from commit 235436d6311ea5ad00edcc1e553012f0736ea86d)
---
 sys/kern/kern_proc.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c
index 61c389f0b345..23d2856a3d32 100644
--- a/sys/kern/kern_proc.c
+++ b/sys/kern/kern_proc.c
@@ -3385,7 +3385,8 @@ allproc_loop:
 		LIST_REMOVE(cp, p_list);
 		LIST_INSERT_AFTER(p, cp, p_list);
 		PROC_LOCK(p);
-		if ((p->p_flag & (P_KPROC | P_SYSTEM | P_TOTAL_STOP)) != 0) {
+		if ((p->p_flag & (P_KPROC | P_SYSTEM | P_TOTAL_STOP |
+		    P_STOPPED_SIG)) != 0) {
 			PROC_UNLOCK(p);
 			continue;
 		}
@@ -3406,6 +3407,16 @@ allproc_loop:
 			PROC_UNLOCK(p);
 			continue;
 		}
+		if ((p->p_flag & P_TRACED) != 0) {
+			/*
+			 * thread_single() below cannot stop traced p,
+			 * so skip it.  OTOH, we cannot require
+			 * restart because debugger might be either
+			 * already stopped or traced as well.
+			 */
+			PROC_UNLOCK(p);
+			continue;
+		}
 		sx_xunlock(&allproc_lock);
 		_PHOLD(p);
 		r = thread_single(p, SINGLE_ALLPROC);