[DTrace-devel] [PATCH v2 3/7] Generate clearer error message when dtrace is run not as root

eugene.loh at oracle.com eugene.loh at oracle.com
Thu Jul 25 05:00:48 UTC 2024


From: Eugene Loh <eugene.loh at oracle.com>

It is a relatively simple mistake to run dtrace not as root, but
the resulting error message is not very clear.  Specifically, it
currently reports a very specific -xlockmem=unlimited message that
is no longer a common failure.  Generate a clearer message.

Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
 cmd/dtrace.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/cmd/dtrace.c b/cmd/dtrace.c
index 9c820686..ab5817ef 100644
--- a/cmd/dtrace.c
+++ b/cmd/dtrace.c
@@ -1036,6 +1036,21 @@ main(int argc, char *argv[])
 		}
 	}
 
+	/*
+	 * Generate a helpful error message if the user forgets to run as root.
+	 *
+	 * Note that DMODE_VERS has already been handled, and DMODE_HEADER and
+	 * DMODE_LINK are okay without root.
+	 *
+	 * Insist on root for tracing, but also for DMODE_LIST and even for
+	 * DMODE_EXEC with g_exec==0, since otherwise too many probes will
+	 * simply not be recognized, likely causing puzzling behavior.
+	 */
+	if (getuid() != 0 && (g_mode == DMODE_LIST || g_mode == DMODE_EXEC)) {
+		fprintf(stderr, "%s: run as root for tracing and listing probes\n", g_pname);
+		return E_USAGE;
+	}
+
 	/*
 	 * If we're in linker mode and the data model hasn't been specified,
 	 * we try to guess the appropriate setting by examining the object
-- 
2.43.5




More information about the DTrace-devel mailing list