Welcome! Log In Create A New Profile

Advanced

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

David CARLIER
January 20, 2022 04:08PM
From 7f3194c36a9788d9b98630773ab907adb110cf6f Mon Sep 17 00:00:00 2001
From: David CARLIER <devnexen@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@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
_______________________________________________
nginx-devel mailing list -- nginx-devel@nginx.org
To unsubscribe send an email to nginx-devel-leave@nginx.org
Subject Author Views Posted

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

David CARLIER 269 January 20, 2022 04:08PM

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

Sergey Kandaurov 125 January 21, 2022 11:22AM

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

David CARLIER 170 January 21, 2022 11:32AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 133
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready