Spdk/scripts/core-collector.sh
Karol Latecki a985a3ae01 test/common: don't specify output dir for core_pattern in command line
Remove output directory argument for core-collector.sh when
setting system core_pattern. Instead save the full output
directory path into a file to a known location and read it
directly in core-collector.sh.

The reason for this change is 128 bytes command line length
for core_pattern (see 'man core 5'). In case working with
long paths the core_pattern command line gets truncated and
core dumps are not generated.

Change-Id: Ia74c180e4923fb43d6ff66129ffe54c32827adca
Signed-off-by: Karol Latecki <karol.latecki@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12755
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Michal Berger <michallinuxstuff@gmail.com>
Reviewed-by: Pawel Piatek <pawelx.piatek@intel.com>
Reviewed-by: Konrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
2022-06-08 17:29:08 +00:00

78 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# We don't want to tell kernel to include %e or %E since these
# can include whitespaces or other funny characters, and working
# with those on the cmdline would be a nightmare. Use procfs for
# the remaining pieces we want to gather:
# |$rootdir/scripts/core-collector.sh %P %s %t %c $output_dir
core_meta() {
jq . <<- CORE
{
"$exe_comm": {
"ts": "$core_time",
"size": "$core_size bytes",
"PID": $core_pid,
"signal": "$core_sig ($core_sig_name)",
"path": "$exe_path",
"statm": "$statm"
}
}
CORE
}
bt() { hash gdb && gdb -batch -ex "thread apply all bt full" "$1" "$2" 2>&1; }
stderr() {
exec 2> "$core.stderr.txt"
set -x
}
args+=(core_pid)
args+=(core_sig)
args+=(core_ts)
args+=(rlimit)
read -r "${args[@]}" <<< "$*"
exe_path=$(readlink -f "/proc/$core_pid/exe")
exe_comm=$(< "/proc/$core_pid/comm")
statm=$(< "/proc/$core_pid/statm")
core_time=$(date -d@"$core_ts")
core_sig_name=$(kill -l "$core_sig")
core=$(< "${0%/*}/../.coredump_path")/${exe_path##*/}_$core_pid.core
stderr
# RLIMIT_CORE is not enforced when core is piped to us. To make
# sure we won't attempt to overload underlying storage, copy
# only the reasonable amount of bytes (systemd defaults to 2G
# so let's follow that). But first, check limits of terminating
# process to see if we need to make any adjustments.
max_core=$((1024 * 1024 * 1024 * 2))
if ((rlimit == 0xffffffffffffffff || rlimit > max_core)); then
rlimit=$max_core
fi
# Clear path for lz
rm -f "$core"{,.{bin,bt,gz,json}}
# Slurp the core
head -c "$rlimit" <&0 > "$core"
core_size=$(wc -c < "$core")
# Compress it
gzip -c "$core" > "$core.gz"
# Save the binary
cp "$exe_path" "$core.bin"
# Save the backtrace
bt "$exe_path" "$core" > "$core.bt.txt"
# Save the metadata of the core
core_meta > "$core.json"
# Nuke the original core
rm "$core"