Check for hanging process at the end of a job.
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Thu, 11 Oct 2018 18:44:27 +0000 (14:44 -0400)
committerJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Thu, 18 Oct 2018 19:26:48 +0000 (15:26 -0400)
Run in all scenarios. We force a coredump and archive it to ./build.

Use ldd on /proc/$PID/exe to get actual dependencies.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
jobs/lttng-tools.yaml
scripts/lttng-tools/build.sh
scripts/lttng-tools/hang_processes.sh [new file with mode: 0755]

index a7471396b486716c6c624a7be0be8c846e0ae2ba..b5d55b1c0d7dc1736a6ff1b775ca992d3be3fd55 100644 (file)
 - lttng-tools_build_publishers_dev: &lttng-tools_build_publishers_dev
     name: 'lttng-tools_build_publishers_dev'
     publishers:
+      - postbuildscript:
+          mark-unstable-if-failed: true
+          builders:
+            - role: SLAVE
+              build-on:
+                  - SUCCESS
+                  - UNSTABLE
+                  - NOT_BUILT
+                  - ABORTED
+                  - FAILURE
+              build-steps:
+                  - shell:
+                      !include-raw-escape: scripts/lttng-tools/hang_processes.sh
       - tap:
           results: 'tap/**/*.tap'
           failed-tests-mark-build-as-failure: true
 - lttng-tools_build_publishers_prod: &lttng-tools_build_publishers_prod
     name: 'lttng-tools_build_publishers_prod'
     publishers:
+      - postbuildscript:
+          mark-unstable-if-failed: true
+          builders:
+            - role: SLAVE
+              build-on:
+                  - SUCCESS
+                  - UNSTABLE
+                  - NOT_BUILT
+                  - ABORTED
+                  - FAILURE
+              build-steps:
+                  - shell:
+                      !include-raw-escape: scripts/lttng-tools/hang_processes.sh
       - tap:
           results: 'tap/**/*.tap'
           failed-tests-mark-build-as-failure: true
index 052eb8d54a9f27632527f56751cdef6101faec29..774f5359451d6e99505ec0a96205ff9166205fa1 100755 (executable)
@@ -342,8 +342,8 @@ if [ "$RUN_TESTS" = "yes" ]; then
     ulimit -c unlimited
 
     # Kill any LTTng-related process
-    lttng_processes="$("$PGREP" -l 'lttng|gen-ust-.+')"
-    if [ $? -eq 0 ]; then
+    lttng_processes="$("$PGREP" -l 'lttng|gen-ust-.+')" || true
+    if [ ! -z "$lttng_processes" ]; then
         echo "The following LTTng processes were detected running on the system and will be killed:"
         echo "$lttng_processes"
 
diff --git a/scripts/lttng-tools/hang_processes.sh b/scripts/lttng-tools/hang_processes.sh
new file mode 100755 (executable)
index 0000000..d64fa9c
--- /dev/null
@@ -0,0 +1,68 @@
+#!/bin/bash -exu
+#
+# Copyright (C) 2018 - Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+PGREP=pgrep
+pids=""
+dependencies=""
+file_list=$(mktemp)
+ret=0
+
+lttng_processes="$("$PGREP" -l 'lttng|gen-ust-.+')" || true
+if [ ! -z "$lttng_processes" ]; then
+
+    pids="$(cut -d ' ' -f 1 <<< "$lttng_processes" | tr '\n' ' ')"
+    comma_pids=$(tr ' ' ',' <<< "$pids")
+    echo "The following LTTng processes were detected running on the system and will be aborted:"
+    echo "$lttng_processes"
+
+    # Stop the processes to make sure everything is frozen
+    kill -SIGSTOP $pids
+
+    # Get dependencies for coredump analysis
+    # Use /proc/$PID/exe and ldd to get all shared libs necessary
+    array=(${pids})
+    # Add the /proc/ prefix using parameter expansion
+    array=("${array[@]/#/\/proc\/}")
+    # Add the /exe suffix using parameter expansion
+    array=("${array[@]/%/\/exe}")
+    dependencies=$(ldd "${array[@]}" | grep -v "not found")
+    dependencies=$(awk '/=>/{print$(NF-1)}' <<< "$dependencies" | sort | uniq)
+
+    kill -SIGABRT $pids
+    kill -SIGCONT $pids
+    ret=1
+fi
+
+core_files=$(find "/tmp" -name "core\.[0-9]*" -type f 2>/dev/null) || true
+if [ ! -z "$core_files" ]; then
+    echo "$core_files" >> "$file_list"
+    echo "$dependencies" >> "$file_list"
+
+    # Make sure the coredump is finished using fuser
+    for core in $core_files; do
+        while fuser "$core"; do
+            sleep 1
+        done
+    done
+
+    tar cfzh "${WORKSPACE}/build/core.tar.gz" -T "$file_list"
+    rm -rf $core_files
+    ret=1
+fi
+
+rm -rf "$file_list"
+exit $ret
This page took 0.031278 seconds and 4 git commands to generate.