ctdb-test: Modify ctdb_io_test test_setup to provide queue reference
[vlendec/samba-autobuild/.git] / ctdb / config / debug-hung-script.sh
index 34e957c3cf0abd5da0c703a597baeaa9db415c8d..03d5ea2f6a0d202ed63e10f81c4280dd8152c94a 100755 (executable)
@@ -1,11 +1,14 @@
 #!/bin/sh
 
+# This script only works on Linux.  Please modify (and submit patches)
+# for other operating systems.
+
 [ -n "$CTDB_BASE" ] || \
-    export CTDB_BASE=$(cd -P $(dirname "$0") ; echo "$PWD")
+    CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; echo "$PWD")
 
-. "$CTDB_BASE/functions"
+. "${CTDB_BASE}/functions"
 
-loadconfig ctdb
+load_script_options
 
 # Testing hook
 if [ -n "$CTDB_DEBUG_HUNG_SCRIPT_LOGFILE" ] ; then
@@ -22,20 +25,22 @@ fi
     echo "===== Start of hung script debug for PID=\"$1\", event=\"$2\" ====="
 
     echo "pstree -p -a ${1}:"
-    out=$(pstree -p -a $1)
+    out=$(pstree -p -a "$1")
     echo "$out"
 
     # Check for processes matching a regular expression and print
     # stack staces.  This could help confirm that certain processes
     # are stuck in certain places such as the cluster filesystem.  The
-    # regexp should separate items with "\|" and should not contain
+    # regexp must separate items with "|" and must not contain
     # parentheses.  The default pattern can be replaced for testing.
-    default_pat='exportfs\|rpcinfo'
+    default_pat='exportfs|rpcinfo'
     pat="${CTDB_DEBUG_HUNG_SCRIPT_STACKPAT:-${default_pat}}"
     echo "$out" |
-    sed -n "s@.*-\(.*${pat}.*\),\([0-9]*\).*@\2 \1@p" |
+    sed -r -n "s@.*-(.*(${pat}).*),([0-9]*).*@\\3 \\1@p" |
     while read pid name ; do
        trace=$(cat "/proc/${pid}/stack" 2>/dev/null)
+       # No! Checking the exit code afterwards is actually clearer...
+       # shellcheck disable=SC2181
        if [ $? -eq 0 ] ; then
            echo "---- Stack trace of interesting process ${pid}[${name}] ----"
            echo "$trace"
@@ -44,7 +49,7 @@ fi
 
     if [ "$2" != "init" ] ; then
        echo "---- ctdb scriptstatus ${2}: ----"
-       ctdb scriptstatus "$2"
+       $CTDB scriptstatus "$2"
     fi
 
     echo "===== End of hung script debug for PID=\"$1\", event=\"$2\" ====="
@@ -53,4 +58,4 @@ fi
        mv "$tmp" "$CTDB_DEBUG_HUNG_SCRIPT_LOGFILE"
     fi
 
-) 9>"${CTDB_VARDIR}/debug-hung-script.lock"
+) 9>"${CTDB_SCRIPT_VARDIR}/debug-hung-script.lock"