ctdb-scripts: Provide a gstack function if gstack is not available
authorMartin Schwenke <martin@meltin.net>
Sat, 2 Dec 2017 09:06:25 +0000 (20:06 +1100)
committerAmitay Isaacs <amitay@samba.org>
Wed, 11 Jul 2018 12:47:21 +0000 (14:47 +0200)
gstack isn't widely available, so provide a simple function that does
the same thing if it gstack can't be found.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Autobuild-User(master): Amitay Isaacs <amitay@samba.org>
Autobuild-Date(master): Wed Jul 11 14:47:21 CEST 2018 on sn-devel-144

ctdb/config/debug_locks.sh

index 086768540880f6291a11c3b489b7fd9f6205e22b..1f89cb7353cb284763e9e83e7b91d8c6a1bb71fe 100755 (executable)
 
 . "${CTDB_BASE}/functions"
 
+# type is at least mentioned in POSIX and more is portable than which(1)
+# shellcheck disable=SC2039
+if ! type gstack >/dev/null 2>&1 ; then
+       gstack ()
+       {
+               _pid="$1"
+
+               gdb -batch --quiet -nx "/proc/${_pid}/exe" "$_pid" \
+                   -ex "thread apply all bt" 2>/dev/null |
+                       grep '^\(#\|Thread \)'
+       }
+fi
+
 # Load/cache database options from configuration file
 ctdb_get_db_options
 
@@ -72,7 +85,6 @@ ctdb_get_db_options
                cat "/proc/${pid}/stack"
            else
                gstack "$pid"
-               # gcore -o /var/log/core-deadlock-ctdb $pid
            fi
        done
     fi