From 7f377cf26ecec10cd77f28c1993c48337279892d Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Mon, 17 Nov 2014 14:15:14 +1100 Subject: [PATCH] ctdb-scripts: Fix stack dumping when debugging hung scripts There are parentheses missing that stop the default pattern from matching commands with trailing garbage (e.g. "exportfs.orig"). A careful check of POSIX (and running GNU sed with --posix) suggests that "\|" isn't a supported way of specifying alternation in a regular expression. Therefore, it is clearer to switch to extended regular expressions so that this has a chance of being portable (even though the point is to print /proc//stack, which only works on Linux). Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs Autobuild-User(master): Amitay Isaacs Autobuild-Date(master): Tue Nov 18 06:37:45 CET 2014 on sn-devel-104 --- ctdb/config/debug-hung-script.sh | 9 ++++++--- ctdb/doc/ctdbd.conf.5.xml | 8 +++++--- ctdb/tests/complex/90_debug_hung_script.sh | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/ctdb/config/debug-hung-script.sh b/ctdb/config/debug-hung-script.sh index 34e957c3cf0..3f800fc5559 100755 --- a/ctdb/config/debug-hung-script.sh +++ b/ctdb/config/debug-hung-script.sh @@ -1,5 +1,8 @@ #!/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") @@ -28,12 +31,12 @@ fi # 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) if [ $? -eq 0 ] ; then diff --git a/ctdb/doc/ctdbd.conf.5.xml b/ctdb/doc/ctdbd.conf.5.xml index cb48d721d06..cf71a3509bd 100644 --- a/ctdb/doc/ctdbd.conf.5.xml +++ b/ctdb/doc/ctdbd.conf.5.xml @@ -1521,11 +1521,13 @@ CTDB_SET_MonitorInterval=20 REGEXP specifies interesting processes for which stack traces should be logged when debugging hung eventscripts - and those processes are matched in pstree output. See - also CTDB_DEBUG_HUNG_SCRIPT. + and those processes are matched in pstree output. REGEXP + is an extended regexp so choices are separated by pipes + ('|'). However, REGEXP should not contain parentheses. + See also CTDB_DEBUG_HUNG_SCRIPT. - Default is "exportfs\|rpcinfo". + Default is "exportfs|rpcinfo". diff --git a/ctdb/tests/complex/90_debug_hung_script.sh b/ctdb/tests/complex/90_debug_hung_script.sh index 543844970ba..09718c4f721 100755 --- a/ctdb/tests/complex/90_debug_hung_script.sh +++ b/ctdb/tests/complex/90_debug_hung_script.sh @@ -58,7 +58,7 @@ ctdb_test_exit_hook_add "onnode $test_node rm -f $debug_output" try_command_on_node -i $test_node tee "$rc_local_f" <<<"\ CTDB_RUN_TIMEOUT_MONITOR=yes CTDB_DEBUG_HUNG_SCRIPT_LOGFILE=\"$debug_output\" -CTDB_DEBUG_HUNG_SCRIPT_STACKPAT='exportfs\|rpcinfo\|sleep'" +CTDB_DEBUG_HUNG_SCRIPT_STACKPAT='exportfs|rpcinfo|sleep'" try_command_on_node $test_node chmod +x "$rc_local_f" -- 2.11.4.GIT