-#############################################
-# update the smb.conf cache in the background
-testparm_background_update() {
- # if the cache doesn't exist, then update in the foreground
- [ -f $smbconf_cache ] || {
- testparm_foreground_update
- }
- # otherwise do a background update
- (
- tmpfile="${smbconf_cache}.$$"
- testparm -s > $tmpfile 2> /dev/null &
- # remember the pid of the teamparm process
- pid="$!"
- # give it 10 seconds to run
- timeleft=10
- while [ $timeleft -gt 0 ]; do
- timeleft=$(($timeleft - 1))
- # see if the process still exists
- /bin/kill -0 $pid > /dev/null 2>&1 || {
- # it doesn't exist, grab its exit status
- wait $pid
- [ $? = 0 ] || {
- echo "50.samba: smb.conf background update exited with status $?"
- rm -f "${tmpfile}"
- exit 1
- }
- # put the new smb.conf contents in the cache (atomic rename)
- # make sure we remove references to the registry while doing
- # this to ensure that running testparm on the cache does
- # not use the registry
- egrep -v 'registry.shares.=|include.=' < "$tmpfile" > "${tmpfile}.2"
- rm -f "$tmpfile"
- mv -f "${tmpfile}.2" "$smbconf_cache" || {
- echo "50.samba: failed to update background cache"
- rm -f "${tmpfile}.2"
- exit 1
- }
- exit 0
- }
- # keep waiting for testparm to finish
- sleep 1
- done
- # it took more than 10 seconds - kill it off
- rm -f "${tmpfile}"
- /bin/kill -9 "$pid" > /dev/null 2>&1
- echo "50.samba: timed out updating smbconf cache in background"
- exit 1
- ) &