[PATCH] workers process making them traceable on FreeBSD 11.x and above

David CARLIER devnexen at gmail.com
Thu Jan 20 21:06:10 UTC 2022


>From 7f3194c36a9788d9b98630773ab907adb110cf6f Mon Sep 17 00:00:00 2001
From: David CARLIER <devnexen at gmail.com>
Date: Thu, 20 Jan 2022 20:56:49 +0000
Subject: [PATCH] process worker, enabling process tracing and core dumping on
 FreeBSD 11.x and above using the procctl native API. Checking the version is
 enough as the functions and the  flag we re interested in are available right
 off the bat.

Signed-off-by: David CARLIER <devnexen at gmail.com>
---
 auto/os/freebsd                  | 11 +++++++++++
 src/os/unix/ngx_freebsd_config.h |  4 ++++
 src/os/unix/ngx_process_cycle.c  | 10 ++++++++++
 3 files changed, 25 insertions(+)

diff --git a/auto/os/freebsd b/auto/os/freebsd
index 870bac4b..8bb086f0 100644
--- a/auto/os/freebsd
+++ b/auto/os/freebsd
@@ -103,3 +103,14 @@ if [ $version -ge 701000 ]; then
     echo " + cpuset_setaffinity() found"
     have=NGX_HAVE_CPUSET_SETAFFINITY . auto/have
 fi
+
+# procctl
+
+
+# the procctl api and its PROC_TRACE_CTL* flags exists from
+# FreeBSD 11.x
+
+if [ $version -ge 1100000 ]; then
+    echo " + procctl() found"
+    have=NGX_HAVE_PROCCTL . auto/have
+fi
diff --git a/src/os/unix/ngx_freebsd_config.h b/src/os/unix/ngx_freebsd_config.h
index c641108b..04ed19ca 100644
--- a/src/os/unix/ngx_freebsd_config.h
+++ b/src/os/unix/ngx_freebsd_config.h
@@ -87,6 +87,10 @@
 #include <sys/event.h>
 #endif

+#if (NGX_HAVE_PROCCTL)
+#include <sys/procctl.h>
+#endif
+

 #if (NGX_HAVE_FILE_AIO)

diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c
index 07cd05e8..c0cf052f 100644
--- a/src/os/unix/ngx_process_cycle.c
+++ b/src/os/unix/ngx_process_cycle.c
@@ -869,6 +869,16 @@ ngx_worker_process_init(ngx_cycle_t *cycle,
ngx_int_t worker)

 #endif

+#if (NGX_HAVE_PROCCTL)
+    /* allow the process being traceable and producing a coredump in
FreeBSD 11.x */
+    ngx_int_t ctl = PROC_TRACE_CTL_ENABLE;
+
+    if (procctl(P_PID, 0, PROC_TRACE_CTL, &ctl) == -1) {
+        ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+                      "procctl(PROC_TRACE_CTL_ENABLE) failed");
+    }
+#endif
+
     if (ccf->working_directory.len) {
         if (chdir((char *) ccf->working_directory.data) == -1) {
             ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
-- 
2.34.1



More information about the nginx-devel mailing list