From: Martin Schwenke Date: Thu, 30 Jul 2015 06:49:35 +0000 (+1000) Subject: ctdb-scripts: Improve error handling for 50.samba testparm failure X-Git-Tag: talloc-2.1.4~430 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7d04778c82a8f657b6ba0173c29529fa03ab7a25;p=thirdparty%2Fsamba.git ctdb-scripts: Improve error handling for 50.samba testparm failure Also add tests. Update testparm stub to fake error and timeout. Add timeout stub. Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- diff --git a/ctdb/config/events.d/50.samba b/ctdb/config/events.d/50.samba index 4b53cba01be..1742ff19249 100755 --- a/ctdb/config/events.d/50.samba +++ b/ctdb/config/events.d/50.samba @@ -78,19 +78,42 @@ testparm_foreground_update () { _timeout="$1" - if ! _out=$(timeout $_timeout testparm -v -s 2>/dev/null) ; then - if [ -f "$smbconf_cache" ] ; then - echo "WARNING: smb.conf cache update failed - using old cache file" - return 1 - else - die "ERROR: smb.conf cache create failed" - fi - fi - + # No need to remove these temporary files, since there are only 2 + # of them. + _out="${smbconf_cache}.out" + _err="${smbconf_cache}.err" + + timeout $_timeout testparm -v -s >"$_out" 2>"$_err" + case $? in + 0) : ;; + 124) + if [ -f "$smbconf_cache" ] ; then + echo "WARNING: smb.conf cache update timed out - using old cache file" + return 1 + else + echo "ERROR: smb.conf cache create failed - testparm command timed out" + exit 1 + fi + ;; + *) + if [ -f "$smbconf_cache" ] ; then + echo "WARNING: smb.conf cache update failed - using old cache file" + cat "$_err" + return 1 + else + echo "ERROR: smb.conf cache create failed - testparm failed with:" + cat "$_err" + exit 1 + fi + esac + + # Only using $$ here to avoid a collision. This is written into + # CTDB's own state directory so there is no real need for a secure + # temporary file. _tmpfile="${smbconf_cache}.$$" # Patterns to exclude... - pat='^[[:space:]]+(registry[[:space:]]+shares|include|copy|winbind[[:space:]]+separator)[[:space:]]+=' - echo "$_out" | grep -Ev "$pat" >"$_tmpfile" + _pat='^[[:space:]]+(registry[[:space:]]+shares|include|copy|winbind[[:space:]]+separator)[[:space:]]+=' + grep -Ev "$_pat" <"$_out" >"$_tmpfile" mv "$_tmpfile" "$smbconf_cache" # atomic return 0 diff --git a/ctdb/tests/eventscripts/50.samba.monitor.110.sh b/ctdb/tests/eventscripts/50.samba.monitor.110.sh new file mode 100755 index 00000000000..21519335674 --- /dev/null +++ b/ctdb/tests/eventscripts/50.samba.monitor.110.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +. "${TEST_SCRIPTS_DIR}/unit.sh" + +define_test "testparm fails" + +setup_samba + +export FAKE_TESTPARM_FAIL="yes" +required_result 1 <&2 <&2 + + cat >&2 <&2 +} + +if [ -n "$FAKE_TESTPARM_FAIL" ] ; then + error +fi + +if [ -n "$FAKE_TIMEOUT" ] ; then + timeout +fi + # Ensure that testparm always uses our canned configuration instead of -# the global one, unless some other file is specified. +# the global one, unless some other file is specified. file="" parameter="" diff --git a/ctdb/tests/eventscripts/stubs/timeout b/ctdb/tests/eventscripts/stubs/timeout new file mode 100755 index 00000000000..1ddce531df4 --- /dev/null +++ b/ctdb/tests/eventscripts/stubs/timeout @@ -0,0 +1,8 @@ +#!/bin/sh + +if [ -n "$FAKE_TIMEOUT" ] ; then + exit 124 +else + shift 1 + exec "$@" +fi