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

Kris Van Hees kris.van.hees at oracle.com
Fri Jul 26 22:44:23 UTC 2024


On Thu, Jul 25, 2024 at 01:00:48AM -0400, eugene.loh--- via DTrace-devel wrote:
> 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>

Reviewed-by: Kris Van Hees <kris.van.hees 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
> 
> 
> _______________________________________________
> DTrace-devel mailing list
> DTrace-devel at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/dtrace-devel



More information about the DTrace-devel mailing list