From 83697aa95e1d3eefe7bbc4da5e77d899be091be2 Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Mon, 27 Sep 2021 21:16:23 +0100 Subject: [PATCH] fpm allow to ptrace/make the the process dumpable for FreeBSD. (#7375) --- sapi/fpm/config.m4 | 13 +++++++++++++ sapi/fpm/fpm/fpm_unix.c | 11 +++++++++++ sapi/fpm/www.conf.in | 3 ++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/sapi/fpm/config.m4 b/sapi/fpm/config.m4 index 7c2fdec1220..af6cae8ca95 100644 --- a/sapi/fpm/config.m4 +++ b/sapi/fpm/config.m4 @@ -25,6 +25,18 @@ AC_DEFUN([AC_FPM_PRCTL], ]) ]) +AC_DEFUN([AC_FPM_PROCCTL], +[ + AC_MSG_CHECKING([for procctl]) + + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], [[procctl(0, 0, 0, 0);]])], [ + AC_DEFINE([HAVE_PROCCTL], 1, [do we have procctl?]) + AC_MSG_RESULT([yes]) + ], [ + AC_MSG_RESULT([no]) + ]) +]) + AC_DEFUN([AC_FPM_CLOCK], [ have_clock_gettime=no @@ -494,6 +506,7 @@ if test "$PHP_FPM" != "no"; then AC_FPM_STDLIBS AC_FPM_PRCTL + AC_FPM_PROCCTL AC_FPM_CLOCK AC_FPM_TRACE AC_FPM_BUILTIN_ATOMIC diff --git a/sapi/fpm/fpm/fpm_unix.c b/sapi/fpm/fpm/fpm_unix.c index 02893b1d498..acf38ce660d 100644 --- a/sapi/fpm/fpm/fpm_unix.c +++ b/sapi/fpm/fpm/fpm_unix.c @@ -15,6 +15,10 @@ #include #endif +#ifdef HAVE_PROCCTL +#include +#endif + #ifdef HAVE_APPARMOR #include #endif @@ -409,6 +413,13 @@ int fpm_unix_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ } #endif +#ifdef HAVE_PROCCTL + int dumpable = PROC_TRACE_CTL_ENABLE; + if (wp->config->process_dumpable && -1 == procctl(P_PID, getpid(), PROC_TRACE_CTL, &dumpable)) { + zlog(ZLOG_SYSERROR, "[pool %s] failed to procctl(PROC_TRACE_CTL)", wp->config->name); + } +#endif + if (0 > fpm_clock_init()) { return -1; } diff --git a/sapi/fpm/www.conf.in b/sapi/fpm/www.conf.in index d13b60067fb..d01753283e9 100644 --- a/sapi/fpm/www.conf.in +++ b/sapi/fpm/www.conf.in @@ -70,7 +70,8 @@ listen = 127.0.0.1:9000 ; Default Value: no set ; process.priority = -19 -; Set the process dumpable flag (PR_SET_DUMPABLE prctl) even if the process user +; Set the process dumpable flag (PR_SET_DUMPABLE prctl for Linux or +; PROC_TRACE_CTL procctl for FreeBSD) even if the process user ; or group is different than the master process user. It allows to create process ; core dump and ptrace the process for the pool user. ; Default Value: no