Skip to contentSkip to conversation

Generate clearer error message when dtrace is run not as root

PATCH In review [email protected] 2 participants 2 messages Jul 25, 2024 – Jul 26, 2024

lore
Share & tools
lore
#0 lore raw

PATCH v2 3/7 Generate clearer error message when dtrace is run not as root

From: Eugene Loh <[email protected]>

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.

---
 cmd/dtrace.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
cmd/dtrace.c +15 -0
index 9c820686..ab5817ef 100644
@@ -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
Signature · 1 line
2.43.5
Reviewed-by on v2 3/7
#1 lore raw
Quoted 8 lines · eugene.loh--- via DTrace-devel

From: Eugene Loh <[email protected]>

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.

Quoted 38 lines
---
 cmd/dtrace.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
cmd/dtrace.c +15 -0
index 9c820686..ab5817ef 100644
@@ -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
Signature · 7 lines
2.43.5


_______________________________________________
DTrace-devel mailing list
[email protected]
https://oss.oracle.com/mailman/listinfo/dtrace-devel