diff options
author | Martin Schwenke <martin@meltin.net> | 2021-01-04 11:54:38 +1100 |
---|---|---|
committer | Amitay Isaacs <amitay@samba.org> | 2021-05-28 06:46:29 +0000 |
commit | ffb56c9143d1d4b9a2dfaa8300be6ce5d6881ab1 (patch) | |
tree | 350b753e0e7aeb32c927a2a27c49f6ba001ef072 /ctdb | |
parent | 55d4b3438f2c44a12b4c513ef26e2d1c4fa9f5b4 (diff) | |
download | samba-ffb56c9143d1d4b9a2dfaa8300be6ce5d6881ab1.tar.gz |
ctdb-scripts: Avoid direct /proc access
The main reason for this is to facilitate testing.
Avoid some /proc accesses entirely by using ps(1) (which can be
replaced by a stub when testing) because this script might as well be
more portable in case anyone wants to add lock debugging for a
non-Linux platform. While the "state" format specification isn't
POSIX-compliant, it works on both Linux and FreeBSD so it is a
reasonable improvement.
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'ctdb')
-rwxr-xr-x | ctdb/config/debug_locks.sh | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/ctdb/config/debug_locks.sh b/ctdb/config/debug_locks.sh index 6f012bd3355..7c5fd50d8aa 100755 --- a/ctdb/config/debug_locks.sh +++ b/ctdb/config/debug_locks.sh @@ -33,10 +33,8 @@ dump_stack () _pid="$1" echo "----- Stack trace for PID=${_pid} -----" - # x is intentionally ignored - # shellcheck disable=SC2034 - read x x state x <"/proc/${_pid}/stat" - if [ "$state" = "D" ] ; then + _state=$(ps -p "$_pid" -o state= | cut -c 1) + if [ "$_state" = "D" ] ; then # Don't run gstack on a process in D state since # gstack will hang until the process exits D state. # Although it is possible for a process to transition @@ -47,7 +45,7 @@ dump_stack () # deadlock... but it will probably give us someone to # blame! echo "----- Process in D state, printing kernel stack only" - cat "/proc/${_pid}/stack" + get_proc "${_pid}/stack" else gstack "$_pid" fi @@ -81,10 +79,11 @@ dump_stacks () # Parse /proc/locks and extract following information # pid process_name tdb_name offsets [W] - out=$( grep -F "POSIX ADVISORY WRITE" /proc/locks | + out=$( get_proc "locks" | + grep -F "POSIX ADVISORY WRITE" | awk '{ if($2 == "->") { print $6, $7, $8, $9, "W" } else { print $5, $6, $7, $8 } }' | while read pid rest ; do - pname=$(readlink "/proc/${pid}/exe") + pname=$(ps -p "$pid" -o comm=) echo "$pid $pname $rest" done | sed -e "$sed_cmd" | grep '\.tdb' ) |