MINOR: proc: setting the process to produce a core dump on FreeBSD.

using the procctl api to set the current process as traceable, thus being able to produce a core dump as well.

making it as compile option if not wished or using freebsd prior to 11.x (last no EOL release).
This commit is contained in:
devnexen@gmail.com 2021-08-21 09:13:10 +01:00 committed by Willy Tarreau
parent ff0f278860
commit 21185970c1
2 changed files with 13 additions and 3 deletions

View File

@ -36,6 +36,7 @@
# USE_ACCEPT4 : enable use of accept4() on linux. Automatic. # USE_ACCEPT4 : enable use of accept4() on linux. Automatic.
# USE_CLOSEFROM : enable use of closefrom() on *bsd, solaris. Automatic. # USE_CLOSEFROM : enable use of closefrom() on *bsd, solaris. Automatic.
# USE_PRCTL : enable use of prctl(). Automatic. # USE_PRCTL : enable use of prctl(). Automatic.
# USE_PROCCTL : enable use of procctl(). Automatic.
# USE_ZLIB : enable zlib library support and disable SLZ # USE_ZLIB : enable zlib library support and disable SLZ
# USE_SLZ : enable slz library instead of zlib (default=enabled) # USE_SLZ : enable slz library instead of zlib (default=enabled)
# USE_CPU_AFFINITY : enable pinning processes to CPU on Linux. Automatic. # USE_CPU_AFFINITY : enable pinning processes to CPU on Linux. Automatic.
@ -311,8 +312,8 @@ use_opts = USE_EPOLL USE_KQUEUE USE_NETFILTER \
USE_GETADDRINFO USE_OPENSSL USE_LUA USE_ACCEPT4 \ USE_GETADDRINFO USE_OPENSSL USE_LUA USE_ACCEPT4 \
USE_CLOSEFROM USE_ZLIB USE_SLZ USE_CPU_AFFINITY USE_TFO USE_NS \ USE_CLOSEFROM USE_ZLIB USE_SLZ USE_CPU_AFFINITY USE_TFO USE_NS \
USE_DL USE_RT USE_DEVICEATLAS USE_51DEGREES USE_WURFL USE_SYSTEMD \ USE_DL USE_RT USE_DEVICEATLAS USE_51DEGREES USE_WURFL USE_SYSTEMD \
USE_OBSOLETE_LINKER USE_PRCTL USE_THREAD_DUMP USE_EVPORTS USE_OT \ USE_OBSOLETE_LINKER USE_PRCTL USE_PROCCTL USE_THREAD_DUMP \
USE_QUIC USE_PROMEX USE_MEMORY_PROFILING USE_EVPORTS USE_OT USE_QUIC USE_PROMEX USE_MEMORY_PROFILING
#### Target system options #### Target system options
# Depending on the target platform, some options are set, as well as some # Depending on the target platform, some options are set, as well as some
@ -391,7 +392,7 @@ endif
ifeq ($(TARGET),freebsd) ifeq ($(TARGET),freebsd)
set_target_defaults = $(call default_opts, \ set_target_defaults = $(call default_opts, \
USE_POLL USE_TPROXY USE_LIBCRYPT USE_THREAD USE_CPU_AFFINITY USE_KQUEUE \ USE_POLL USE_TPROXY USE_LIBCRYPT USE_THREAD USE_CPU_AFFINITY USE_KQUEUE \
USE_ACCEPT4 USE_CLOSEFROM USE_GETADDRINFO) USE_ACCEPT4 USE_CLOSEFROM USE_GETADDRINFO USE_PROCCTL)
endif endif
# DragonFlyBSD 4.3 and above # DragonFlyBSD 4.3 and above

View File

@ -70,6 +70,10 @@
#include <sys/prctl.h> #include <sys/prctl.h>
#endif #endif
#if defined(USE_PROCCTL)
#include <sys/procctl.h>
#endif
#ifdef DEBUG_FULL #ifdef DEBUG_FULL
#include <assert.h> #include <assert.h>
#endif #endif
@ -3401,6 +3405,11 @@ int main(int argc, char **argv)
if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1) if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1)
ha_warning("[%s.main()] Failed to set the dumpable flag, " ha_warning("[%s.main()] Failed to set the dumpable flag, "
"no core will be dumped.\n", argv[0]); "no core will be dumped.\n", argv[0]);
#elif defined(USE_PROCCTL)
int traceable = PROC_TRACE_CTL_ENABLE;
if (procctl(P_PID, getpid(), PROC_TRACE_CTL, &traceable) == -1)
ha_warning("[%s.main()] Failed to set the traceable flag, "
"no core will be dumped.\n", argv[0]);
#endif #endif
} }