Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Jul 2023 15:36:17 GMT
From:      Eric van Gyzen <vangyzen@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: dad11f990e2b - main - dtrace: prevent forked child from running after an error condition
Message-ID:  <202307121536.36CFaHGH042785@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by vangyzen:

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

commit dad11f990e2b84b55c440a42c42040f6f0821027
Author:     Eric van Gyzen <vangyzen@FreeBSD.org>
AuthorDate: 2023-07-11 17:58:29 +0000
Commit:     Eric van Gyzen <vangyzen@FreeBSD.org>
CommitDate: 2023-07-12 15:33:28 +0000

    dtrace: prevent forked child from running after an error condition
    
    The pid/killonerror test uses an invalid probe specifier to verify that
    the child process is killed.  It occasionally fails because the "date"
    command is allowed to run long enough to print the date.  This is harmless
    in this case, but is clearly not ideal.
    
    When the dt_proc_control thread is about to exit, and the dtrace command
    forked the child, do not make the child runnable.
    
    Reviewed by:    markj
    MFC after:      1 week
    Sponsored by:   Dell EMC Isilon
    Differential Revision:  https://reviews.freebsd.org/D40976
---
 cddl/contrib/opensolaris/lib/libdtrace/common/dt_proc.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_proc.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_proc.c
index 34bcc15b9ac7..02b63c0a788a 100644
--- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_proc.c
+++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_proc.c
@@ -685,9 +685,19 @@ pwait_locked:
 			break;
 		}
 
-		if (Pstate(P) != PS_UNDEAD && Psetrun(P, 0, 0) == -1) {
-			dt_dprintf("pid %d: failed to set running: %s\n",
-			    (int)dpr->dpr_pid, strerror(errno));
+		if (Pstate(P) != PS_UNDEAD) {
+			if (dpr->dpr_quit && (proc_getflags(P) & PR_KLC)) {
+				/*
+				 * We're about to kill the child, so don't
+				 * bother resuming it.  In some cases, such as
+				 * an initialization error, we shouldn't have
+				 * started it in the first place, so letting it
+				 * run could be harmful.
+				 */
+			} else if (Psetrun(P, 0, 0) == -1) {
+				dt_dprintf("pid %d: failed to set running: "
+				    "%s\n", (int)dpr->dpr_pid, strerror(errno));
+			}
 		}
 
 		(void) pthread_mutex_unlock(&dpr->dpr_lock);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202307121536.36CFaHGH042785>