hang_processes.sh: Fix some ShellCheck warnings
[lttng-ci.git] / scripts / lttng-tools / hang_processes.sh
CommitLineData
0a028cf6
JR
1#!/bin/bash -exu
2#
3# Copyright (C) 2018 - Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18PGREP=pgrep
19pids=""
20dependencies=""
21file_list=$(mktemp)
22ret=0
23
6b95a7b4
SM
24# WORKSPACE is normally set by Jenkins. Use the current directory otherwise,
25# like when testing this script manually.
26WORKSPACE=${WORKSPACE:-$PWD}
27
0a028cf6 28lttng_processes="$("$PGREP" -l 'lttng|gen-ust-.+')" || true
d4069651 29if [ -n "$lttng_processes" ]; then
0a028cf6
JR
30
31 pids="$(cut -d ' ' -f 1 <<< "$lttng_processes" | tr '\n' ' ')"
0a028cf6
JR
32 echo "The following LTTng processes were detected running on the system and will be aborted:"
33 echo "$lttng_processes"
34
35 # Stop the processes to make sure everything is frozen
36 kill -SIGSTOP $pids
37
38 # Get dependencies for coredump analysis
39 # Use /proc/$PID/exe and ldd to get all shared libs necessary
40 array=(${pids})
41 # Add the /proc/ prefix using parameter expansion
42 array=("${array[@]/#/\/proc\/}")
43 # Add the /exe suffix using parameter expansion
44 array=("${array[@]/%/\/exe}")
45 dependencies=$(ldd "${array[@]}" | grep -v "not found")
46 dependencies=$(awk '/=>/{print$(NF-1)}' <<< "$dependencies" | sort | uniq)
47
48 kill -SIGABRT $pids
49 kill -SIGCONT $pids
50 ret=1
51fi
52
53core_files=$(find "/tmp" -name "core\.[0-9]*" -type f 2>/dev/null) || true
d4069651 54if [ -n "$core_files" ]; then
0a028cf6
JR
55 echo "$core_files" >> "$file_list"
56 echo "$dependencies" >> "$file_list"
57
58 # Make sure the coredump is finished using fuser
59 for core in $core_files; do
60 while fuser "$core"; do
61 sleep 1
62 done
63 done
64
6b95a7b4 65 mkdir -p "${WORKSPACE}/build"
0a028cf6 66 tar cfzh "${WORKSPACE}/build/core.tar.gz" -T "$file_list"
d4069651 67 rm -f "$core_files"
0a028cf6
JR
68 ret=1
69fi
70
71rm -rf "$file_list"
72exit $ret
This page took 0.025709 seconds and 4 git commands to generate.