From ee305bcd3ef7da59cdf3ca1ee62d4ff64b6583bb Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Sun, 6 Nov 2022 10:50:01 +1100 Subject: Fix tracing disable on FreeBSD. Some versions of FreeBSD do not support using id 0 to refer to the current pid for procctl, so pass getpid() explicitly. From emaste at freebsd.org. --- platform-tracing.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/platform-tracing.c b/platform-tracing.c index c2810f2d..80488bf7 100644 --- a/platform-tracing.c +++ b/platform-tracing.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "log.h" @@ -42,7 +43,16 @@ platform_disable_tracing(int strict) /* On FreeBSD, we should make this process untraceable */ int disable_trace = PROC_TRACE_CTL_DISABLE; - if (procctl(P_PID, 0, PROC_TRACE_CTL, &disable_trace) && strict) + /* + * On FreeBSD, we should make this process untraceable. + * pid=0 means "this process" and but some older kernels do not + * understand that, so retry with our own pid before failing. + */ + if (procctl(P_PID, 0, PROC_TRACE_CTL, &disable_trace) == 0) + return; + if (procctl(P_PID, getpid(), PROC_TRACE_CTL, &disable_trace) == 0) + return; + if (strict) fatal("unable to make the process untraceable: %s", strerror(errno)); #endif -- cgit v1.2.3