{
_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
--- /dev/null
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "testparm fails"
+
+setup_samba
+
+export FAKE_TESTPARM_FAIL="yes"
+required_result 1 <<EOF
+ERROR: smb.conf cache create failed - testparm failed with:
+Load smb config files from ${CTDB_ETCDIR}/samba/smb.conf
+rlimit_max: increasing rlimit_max (2048) to minimum Windows limit (16384)
+Processing section "[1_existing]"
+Processing section "[2_existing]"
+Processing section "[3_existing]"
+Loaded services file OK.
+WARNING: 'workgroup' and 'netbios name' must differ.
+EOF
+simple_test
--- /dev/null
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "testparm fails on 2nd time through"
+
+setup_samba
+
+ok_null
+simple_test
+
+export FAKE_TESTPARM_FAIL="yes"
+required_result 1 <<EOF
+WARNING: smb.conf cache update failed - using old cache file
+Load smb config files from ${CTDB_ETCDIR}/samba/smb.conf
+rlimit_max: increasing rlimit_max (2048) to minimum Windows limit (16384)
+Processing section "[1_existing]"
+Processing section "[2_existing]"
+Processing section "[3_existing]"
+Loaded services file OK.
+WARNING: 'workgroup' and 'netbios name' must differ.
+
+Failed to set smb ports
+EOF
+simple_test
--- /dev/null
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "testparm times out"
+
+setup_samba
+
+export FAKE_TIMEOUT="yes"
+required_result 1 <<EOF
+ERROR: smb.conf cache create failed - testparm command timed out
+EOF
+simple_test
--- /dev/null
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "testparm times out on 2nd time through"
+
+setup_samba
+
+ok_null
+simple_test
+
+export FAKE_TIMEOUT="yes"
+ok <<EOF
+WARNING: smb.conf cache update timed out - using old cache file
+EOF
+simple_test
exit 2
}
+error ()
+{
+ cat >&2 <<EOF
+Load smb config files from ${CTDB_ETCDIR}/samba/smb.conf
+rlimit_max: increasing rlimit_max (2048) to minimum Windows limit (16384)
+EOF
+
+ for i in $FAKE_SHARES ; do
+ bi=$(basename "$i")
+ echo "Processing section \"[${bi}]\""
+ done >&2
+
+ cat >&2 <<EOF
+Loaded services file OK.
+WARNING: 'workgroup' and 'netbios name' must differ.
+
+EOF
+
+ exit 1
+}
+
+timeout ()
+{
+ echo "$0: INTERNAL ERROR - timeout stub should avoid this" >&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=""
--- /dev/null
+#!/bin/sh
+
+if [ -n "$FAKE_TIMEOUT" ] ; then
+ exit 124
+else
+ shift 1
+ exec "$@"
+fi