Source: rsync
Version: 3.1.1-3
Tags: patch
User: la...@debian.org
Usertags: initscript-stop-action

Hi,

rsync's initscript does not check whether the rsync process has actually 
terminated before returning successfully.

This can result in a non-deterministic race condition where resources that are 
required by the corresponding "start" action (eg. TCP ports, exclusive 
filesystem locks, etc.) are not yet available to the new instance because the 
older process is still releasing them in the background.

This then results in the new process failing to start which is often hidden 
from the sysadmin unless a monitoring system is in use.

For the same/parallel reasons, the stop and restart actions should return a 
non-zero exit code if the daemon failed to stop. Note that adding "sleep" calls 
merely masks the problem and is not a valid fix.

Patch attached.


Regards,

-- 
      ,''`.
     : :'  :     Chris Lamb
     `. `'`      la...@debian.org / chris-lamb.co.uk
       `-
diff --git a/debian/init.d b/debian/init.d
index 3bf5167..3cb0447 100644
--- a/debian/init.d
+++ b/debian/init.d
@@ -111,8 +111,13 @@ case "$1" in
        ;;
   stop)
        log_daemon_msg "Stopping rsync daemon" "rsync"
-       start-stop-daemon --stop --quiet --oknodo --pidfile $RSYNC_PID_FILE
-       log_end_msg $?
+       start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile 
$RSYNC_PID_FILE
+       RETVAL="$?"
+       log_end_msg $RETVAL
+       if [ $RETVAL != 0 ]
+       then
+               exit 1
+       fi
        rm -f $RSYNC_PID_FILE
        ;;
 
@@ -126,8 +131,7 @@ case "$1" in
        if $RSYNC_ENABLE; then
            log_daemon_msg "Restarting rsync daemon" "rsync"
            if [ -s $RSYNC_PID_FILE ] && kill -0 $(cat $RSYNC_PID_FILE) 
>/dev/null 2>&1; then
-               start-stop-daemon --stop --quiet --oknodo --pidfile 
$RSYNC_PID_FILE || true
-               sleep 1
+               start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile 
$RSYNC_PID_FILE
            else
                log_warning_msg "rsync daemon not running, attempting to start."
                rm -f $RSYNC_PID_FILE

Reply via email to