aboutsummaryrefslogtreecommitdiff
path: root/tcwg-base
diff options
context:
space:
mode:
authorThiago Jung Bauermann <thiago.bauermann@linaro.org>2023-10-05 12:24:15 -0300
committerThiago Jung Bauermann <thiago.bauermann@linaro.org>2023-10-05 17:04:51 -0300
commit4d25caf3f8f3ef533a95f19b27c4d446e30a6fef (patch)
tree54393988efa705921ae90788a50e0e3c8e354558 /tcwg-base
parentfde403b8b62e8481ed6ff2e8e70ac4691c731477 (diff)
tcwg-host: Fix kernel core pattern setting for the GDB testsuite
When starting the host container, take the opportunity to check and fix the kernel.core_pattern sysctl to allow the GDB testsuite to check core files. Change-Id: I1ef94220f7c4a76622d0edd33ad6026cf3a619ee
Diffstat (limited to 'tcwg-base')
-rwxr-xr-xtcwg-base/tcwg-host/start.sh28
1 files changed, 26 insertions, 2 deletions
diff --git a/tcwg-base/tcwg-host/start.sh b/tcwg-base/tcwg-host/start.sh
index 5dd9928c..96095def 100755
--- a/tcwg-base/tcwg-host/start.sh
+++ b/tcwg-base/tcwg-host/start.sh
@@ -99,7 +99,8 @@ case "$(uname -m):$($DOCKER --version | cut -d" " -f3)" in
esac
# Since we're starting a host container, take the opportunity to ensure that GDB
-# can attach to test programs when running the testsuite.
+# can attach to test programs when running the testsuite, and that core files
+# are being correctly stored in the filesystem.
(
# Use "sudo sysctl" because there's no guarantee that this script is
# running as root. And there's no guarantee that "sudo sysctl" will
@@ -108,13 +109,36 @@ esac
set +e
ptrace_scope=$(sudo sysctl -n kernel.yama.ptrace_scope)
res=$?
+ ptrace_scope_config=""
# If sysctl above failed (e.g., because this is a non-privileged
# jenkins container), then do not attempt to change system configuration.
if [ $res = 0 ] && [ "$ptrace_scope" != 0 ]; then
set -e
sudo sysctl -we kernel.yama.ptrace_scope=0
+ ptrace_scope_config="kernel.yama.ptrace_scope = 0"
+ fi
+
+ core_pattern=$(sudo sysctl -n kernel.core_pattern)
+ res=$?
+ core_pattern_config=""
+ # If sysctl above failed (e.g., because this is a non-privileged
+ # jenkins container), then do not attempt to change system configuration.
+ if [ $res = 0 ] && echo "$core_pattern" | grep -q -v -e '^core'; then
+ set -e
+ sudo sysctl -we kernel.core_pattern=core.%e.%p.%h.%t
+ core_pattern_config="
+# %e: executable filename
+# %p: PID
+# %h: hostname
+# %t: UNIX time of dump
+kernel.core_pattern = core.%e.%p.%h.%t"
+ fi
+
+ # If any sysctl change was made, persist it in a configuration file.
+ if [ -n "$ptrace_scope_config" ] || [ -n "$core_pattern_config" ]; then
sudo tee /etc/sysctl.d/90-tcwg.conf > /dev/null <<EOF
-kernel.yama.ptrace_scope = 0
+$ptrace_scope_config
+$core_pattern_config
EOF
sudo chmod 644 /etc/sysctl.d/90-tcwg.conf
fi