[DTrace-devel] [PATCH 3/7] libproc: fix Ptrace() error returns

Nick Alcock nick.alcock at oracle.com
Wed Mar 20 14:15:33 UTC 2024


Ptrace() is defined to return a positive number (really zero) on success or
a negative number on error.  Those relatively few call sites that can do
anything useful when Ptrace() fails all do negative-number checks...

... so it's a shame that it also sometimes returns, uh, PS_DEAD, which is,
uh, 4, and sometimes returns an errno, which is a positive number.

Negate the latter and make a dead process return -ECHILD.

Signed-off-by: Nick Alcock <nick.alcock at oracle.com>
---
 libproc/Pcontrol.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libproc/Pcontrol.c b/libproc/Pcontrol.c
index 790b62428f097..1a19601411c8e 100644
--- a/libproc/Pcontrol.c
+++ b/libproc/Pcontrol.c
@@ -1348,7 +1348,7 @@ Ptrace(struct ps_prochandle *P, int stopped)
 			return 0;
 
 		if (P->state == PS_DEAD)
-			return PS_DEAD;
+			return -ECHILD;
 
 		listen_interrupt = P->listening;
 		P->ptrace_halted = TRUE;
@@ -1407,7 +1407,7 @@ Ptrace(struct ps_prochandle *P, int stopped)
 
 	return err;
 err:
-	err = errno;
+	err = -errno;
 err2:
 	/*
 	 * Note a subtlety here: the Ptrace_count may have been reduced, and the state
-- 
2.44.0.273.ge0bd14271f




More information about the DTrace-devel mailing list