From: Hugo Villeneuve Date: Thu, 29 Aug 2013 02:18:59 +0000 (-0400) Subject: Fix bug preventing clean unmounting of rootfs X-Git-Url: http://gitweb.hugovil.com/?a=commitdiff_plain;h=2ae8d010cef72cd9f12c7ca3cf9260ffe68fa4ca;p=hvlinux.git Fix bug preventing clean unmounting of rootfs --- diff --git a/stage1/bootscripts/rc b/stage1/bootscripts/rc index f747bc8..f9654f5 100755 --- a/stage1/bootscripts/rc +++ b/stage1/bootscripts/rc @@ -85,65 +85,83 @@ fi # If so, first collect all the K* scripts in the new run level. if [ ${previous} != N ]; then for kill_script in $(ls /etc/rc.d/rc${runlevel}.d/K* 2> /dev/null); do - if [ -f ${kill_script} ]; then - # "suffix" will contain the script name without the leading Kxx. - suffix="${kill_script##*/K[0-9][0-9]}" - - # If there is a S script in the previous runlevel corresponding - # to this K script, determine what it's full path is. - previous_start="/etc/rc.d/rc${previous}.d/S[0-9][0-9]${suffix}" - - # If no start script was found in the previous run level it could - # be that something was started in rcsysinit.d (sysinit level) so we'll - # determine the path for that possibility as well. - sysinit_start="/etc/rc.d/rcsysinit.d/S[0-9][0-9]${suffix}" - - # Stop the service if there is a start script in the previous run - # level or in the sysinit level. Otherwise, don't execute this K - # script because the service is not active. - if [ -f ${previous_start} -o -f ${sysinit_start} ]; then - startup ${kill_script} stop - retval=${?} - if [ ${retval} -ne ${EXIT_CODE_SUCCESS} -a ${retval} -ne ${EXIT_CODE_WARNING} ]; then - print_error_msg ${kill_script} ${retval} - fi - fi + check_script_status ${kill_script} + if [ ${?} != ${EXIT_CODE_SUCCESS} ]; then + continue + fi + + # "suffix" will contain the script name without the leading Kxx. + suffix="${kill_script##*/K[0-9][0-9]}" + + # If there is a S script in the previous runlevel corresponding + # to this K script, determine what it's full path is. + previous_start="/etc/rc.d/rc${previous}.d/S[0-9][0-9]${suffix}" + + # If no start script was found in the previous run level it could + # be that something was started in rcsysinit.d (sysinit level) so we'll + # determine the path for that possibility as well. + sysinit_start="/etc/rc.d/rcsysinit.d/S[0-9][0-9]${suffix}" + + # Stop the service if there is a start script in the previous run + # level or in the sysinit level. Otherwise, don't execute this K + # script because the service is not active. + if [ "${runlevel}" != "0" -a "${runlevel}" != "6" ]; then + if [ ! -f ${previous_start} -a ! -f ${sysinit_start} ]; then + echo "Warning: script ${kill_script} cannot be stopped because it was not started" + echo "in the previous runlevel" + continue + fi + fi + + startup ${kill_script} stop + retval=${?} + if [ ${retval} -ne ${EXIT_CODE_SUCCESS} -a ${retval} -ne ${EXIT_CODE_WARNING} ]; then + print_error_msg ${kill_script} ${retval} fi done fi # Now run the START scripts for this runlevel. for start_script in $(ls /etc/rc.d/rc${runlevel}.d/S* 2> /dev/null); do - # "suffix" will contain the script name without the leading Sxx. - suffix=${start_script#/etc/rc.d/rc${runlevel}.d/S[0-9][0-9]} + if [ "${previous}" != "N" ]; then + # "suffix" will contain the script name without the leading Sxx. + suffix=${start_script#/etc/rc.d/rc${runlevel}.d/S[0-9][0-9]} - # If there is a K script in the current runlevel corresponding - # to this S script, determine what it's full path is. - current_stop=/etc/rc.d/rc${runlevel}.d/K[0-9][0-9]${suffix} + # If there is a K script in the current runlevel corresponding + # to this S script, determine what it's full path is. + current_stop=/etc/rc.d/rc${runlevel}.d/K[0-9][0-9]${suffix} - if [ ${previous} != "N" ]; then # If there is a S script in the previous runlevel corresponding # to this S script, determine what it's full path is. previous_start=/etc/rc.d/rc${previous}.d/S[0-9][0-9]${suffix} - else - previous_start="" + + if [ -f ${previous_start} -a ! -f ${current_stop} ]; then + # If the service was started in the previous level and was not stopped + # in this runlevel, then we don't have to re-start it. + continue + fi fi - if [ -f "$previous_start" -a ! -f "$current_stop" ]; then - # If the service was started in the previous level and was not stopped - # in this runlevel, then we don't have to re-start it. - continue - else - # If the service was not started in the previous level, or if we just - # stopped it in this runlevel, then we need to start or restart it. - check_script_status ${start_script} - if [ ${?} == ${EXIT_CODE_SUCCESS} ]; then - startup ${start_script} start - retval=${?} - if [ ${retval} -ne ${EXIT_CODE_SUCCESS} -a ${retval} -ne ${EXIT_CODE_WARNING} ]; then - print_error_msg ${start_script} ${retval} - fi - fi + check_script_status ${start_script} + if [ ${?} != ${EXIT_CODE_SUCCESS} ]; then + continue + fi + + # If the service was not started in the previous level, or if we just + # stopped it in this runlevel, then we need to start or restart it. + + case ${runlevel} in + 0|6) + startup ${start_script} stop + ;; + *) + startup ${start_script} start + ;; + esac + + retval=${?} + if [ ${retval} -ne ${EXIT_CODE_SUCCESS} -a ${retval} -ne ${EXIT_CODE_WARNING} ]; then + print_error_msg ${start_script} ${retval} fi done diff --git a/stage1/bootscripts/sendsignals b/stage1/bootscripts/sendsignals index c546fe5..d1a06a2 100755 --- a/stage1/bootscripts/sendsignals +++ b/stage1/bootscripts/sendsignals @@ -8,10 +8,14 @@ source /etc/rc.d/init.d/functions log_script_name "$0 $*" # Send all the remaining processes the TERM signal -cmd_run_log_box "Sending all processes the TERM signal" /sbin/killall5 -15 +cmd_run_log_box_warn "Sending all processes the TERM signal" /sbin/killall5 -15 -# Send all the remaining process (after sending them the TERM signal before) +sleep 2 + +# Send all the remaining processes (after sending them the TERM signal before) # the KILL signal. -cmd_run_log_box "Sending all processes the KILL signal" /sbin/killall5 -9 +cmd_run_log_box_warn "Sending all processes the KILL signal" /sbin/killall5 -9 + +sleep 2 exit $? diff --git a/stage1/install-bootscripts b/stage1/install-bootscripts index 4dbff41..15f22e8 100755 --- a/stage1/install-bootscripts +++ b/stage1/install-bootscripts @@ -34,16 +34,20 @@ bootscript_add_rcsysinit mountkernfs 15 00 bootscript_add_rcsysinit modules 20 00 bootscript_add_rcsysinit udev 25 00 bootscript_add_rcsysinit checkfs 30 00 -bootscript_add_rcsysinit mountfs 35 95 -bootscript_add_rcsysinit swap 40 94 +bootscript_add_rcsysinit mountfs 35 00 +bootscript_add_rcsysinit swap 40 00 bootscript_add_rcsysinit cleanfs 45 00 # rc0.d -bootscript_add_manual 0 sendsignals 95 00 +bootscript_add_manual 0 sendsignals 60 00 +bootscript_add_manual 0 swap 65 00 +bootscript_add_manual 0 mountfs 70 00 bootscript_add_manual 0 halt 99 00 # rc6.d is almost identical to rc0.d -bootscript_add_manual 6 sendsignals 95 00 +bootscript_add_manual 6 sendsignals 60 00 +bootscript_add_manual 6 swap 65 00 +bootscript_add_manual 6 mountfs 70 00 bootscript_add_manual 6 reboot 99 00 exit $?