From 825bb041251952ecc17ae2cfd184b46958924aba Mon Sep 17 00:00:00 2001 From: Gordon Tetlow Date: Thu, 13 Jun 2002 22:30:02 +0000 Subject: [PATCH] Add the final bits that allow the use of rc.d. Note that you can toggle between rc.d and the classic boot scripts based on the rcng variable in your rc.conf. Defaults to classic boot scripts. Submitted by: Mike Makonnen --- etc/rc | 55 +++++++++++++++++++++++++++++++++++++++++++++++-- etc/rc.shutdown | 51 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 2 deletions(-) diff --git a/etc/rc b/etc/rc index eb6aec1e8c4e..25f07a1eea85 100644 --- a/etc/rc +++ b/etc/rc @@ -46,12 +46,63 @@ stty status '^T' trap : 2 trap : 3 # shouldn't be needed -bootmode=$1 - HOME=/ PATH=/sbin:/bin:/usr/sbin:/usr/bin export HOME PATH +# If there is a global system configuration file, suck it in. +# XXX - The only purpose of duplicating it here is to catch rc_ng="YES" +# +if [ -r /etc/defaults/rc.conf ]; then + . /etc/defaults/rc.conf + source_rc_confs +elif [ -r /etc/rc.conf ]; then + . /etc/rc.conf +fi + +# Diskless setups have to depend on a different mechanism since +# their config files haven't been retargeted yet. +# +[ -e /.rcng_yes ] && rc_ng="YES" + +case ${rc_ng} in +[Yy][Ee][Ss]) + . /etc/rc.subr + + # Load system configuration files. The 'XXX' is there because + # the function requires an argument that we don't need to use. + # + load_rc_config 'XXX' + + if [ "$1" = autoboot ]; then + autoboot=yes + _boot="faststart" + rc_fast=yes # run_rc_command(): do fast booting + export autoboot + export rc_fast + else + autoboot=no + _boot="start" + fi + + os=`eval ${CMD_OSTYPE}` + files=`rcorder -k ${os} -s nostart /etc/rc.d/*` + + for _rc_elem in ${files}; do + run_rc_script ${_rc_elem} ${_boot} + done + + echo '' + date + exit 0 + ;; +*) + # fall-through to the old rc scripts + ;; +esac + +bootmode=$1 + # BOOTP diskless boot. We have to run the rc file early in order to # retarget various config files. # diff --git a/etc/rc.shutdown b/etc/rc.shutdown index 25c1e429a83f..0f4bd3db2c1d 100644 --- a/etc/rc.shutdown +++ b/etc/rc.shutdown @@ -44,6 +44,7 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin export HOME PATH # If there is a global system configuration file, suck it in. +# XXX - It's only purpose is to catch rc_ng="YES". # if [ -r /etc/defaults/rc.conf ]; then . /etc/defaults/rc.conf @@ -52,6 +53,56 @@ elif [ -r /etc/rc.conf ]; then . /etc/rc.conf fi +case ${rc_ng} in +[Yy][Ee][Ss]) + . /etc/rc.subr + + load_rc_config 'XXX' + + # If requested, start a watchdog timer in the background which + # will terminate rc.shutdown if rc.shutdown doesn't complete + # within the specified time. + # + _rcshutdown_watchdog= + if [ -n "$rcshutdown_timeout" ]; then + debug "Initiating watchdog timer." + sleep $rcshutdown_timeout && ( + _msg="$rcshutdown_timeout second watchdog" \ + " timeout expired. Shutdown terminated." + logger -t rc.shutdown "$_msg" + echo "$_msg" + date + kill -KILL $$ >/dev/null 2>&1 + ) & + _rcshutdown_watchdog=$! + fi + + # Determine the shutdown order of the /etc/rc.d scripts, + # and perform the operation + # XXX - rcorder(8) with multiple -k switches works as a logical OR, + # so, we can't do this: rcorder -k shutdown -k FreeBSD. + # + files=`eval grep -l \'^# KEYWORD:.*FreeBSD\' \`rcorder -k shutdown /etc/rc.d/*\`` + + for _rc_elem in `reverse_list $files`; do + debug "run_rc_script $_rc_elem stop" + run_rc_script $_rc_elem stop + done + + # Terminate the background watchdog timer (if it is running) + # + if [ -n "$_rcshutdown_watchdog" ]; then + kill -TERM $_rcshutdown_watchdog >/dev/null 2>&1 + fi + + echo '.' + exit 0 + ;; +*) + # fall-through to the old rc scripts + ;; +esac + # reverse_list list # print the list in reverse order #