ctdb-scripts: Quote some variable expansions
[nivanova/samba-autobuild/.git] / ctdb / config / events.d / 50.samba
index 4b53cba01be6f9736a25a2509df692755fc7b73a..7c3a804475fe0819a9279f7837af8952ae36d7d2 100755 (executable)
@@ -2,9 +2,9 @@
 # ctdb event script for Samba
 
 [ -n "$CTDB_BASE" ] || \
-    export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD")
+    CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD")
 
-. $CTDB_BASE/functions
+. "${CTDB_BASE}/functions"
 
 detect_init_style
 
@@ -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
@@ -100,7 +123,7 @@ testparm_background_update ()
 {
     _timeout="$1"
 
-    testparm_foreground_update $_timeout >/dev/null 2>&1 </dev/null &
+    testparm_foreground_update "$_timeout" >/dev/null 2>&1 </dev/null &
 }
 
 testparm_cat ()