hang_processes.sh: Set WORKSPACE variable when running outside of
[lttng-ci.git] / scripts / lttng-tools / hang_processes.sh
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
18 PGREP=pgrep
19 pids=""
20 dependencies=""
21 file_list=$(mktemp)
22 ret=0
23
24 # WORKSPACE is normally set by Jenkins. Use the current directory otherwise,
25 # like when testing this script manually.
26 WORKSPACE=${WORKSPACE:-$PWD}
27
28 lttng_processes="$("$PGREP" -l 'lttng|gen-ust-.+')" || true
29 if [ ! -z "$lttng_processes" ]; then
30
31 pids="$(cut -d ' ' -f 1 <<< "$lttng_processes" | tr '\n' ' ')"
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
51 fi
52
53 core_files=$(find "/tmp" -name "core\.[0-9]*" -type f 2>/dev/null) || true
54 if [ ! -z "$core_files" ]; then
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
65 mkdir -p "${WORKSPACE}/build"
66 tar cfzh "${WORKSPACE}/build/core.tar.gz" -T "$file_list"
67 rm -rf $core_files
68 ret=1
69 fi
70
71 rm -rf "$file_list"
72 exit $ret
This page took 0.071431 seconds and 5 git commands to generate.