From 9edde3e265efe6f481f195bcf706e6ab6d5a88f0 Mon Sep 17 00:00:00 2001 From: Christian Heim Date: Thu, 9 Mar 2006 10:07:19 +0000 Subject: Merging r1939 svn path=/baselayout-vserver/branches/baselayout-1_12/; revision=276 --- ChangeLog | 19 ++++ ChangeLog.vserver | 21 ++++ bin/rc-status | 2 - net-scripts/init.d/net.lo | 4 +- net-scripts/net.modules.d/iwconfig | 16 ++- sbin/depscan.sh | 73 ++++++++----- sbin/env-update.sh | 10 +- sbin/functions.sh | 88 +++++++++------- sbin/rc | 26 +++-- sbin/rc-daemon.sh | 8 +- sbin/rc-help.sh | 10 +- sbin/rc-services.sh | 25 +++-- sbin/runscript.sh | 211 ++++++++++++++++++------------------- src/awk/cachedepends.awk | 18 ++-- src/awk/gendepends.awk | 12 ++- 15 files changed, 304 insertions(+), 239 deletions(-) diff --git a/ChangeLog b/ChangeLog index 812cada..b649171 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,25 @@ # ChangeLog for Gentoo System Intialization ("rc") scripts # Copyright 1999-2006 Gentoo Foundation; Distributed under the GPLv2 + 07 Mar 2006; Roy Marples : + + Set essid to "" instead of -- off as it appears not all drivers work + as they should. Hopefully fixes #125067 and maybe #120822. + + 02 Mar 2006; Roy Marples : + + $myservice is now deprecated for init scripts. + $SVCNAME should be used instead and is read-only so it cannot be + clobbered. + + Several variables in global scope that provided functions rely on, + such as BOOTLEVEL, SOFTLEVEL and svcdir are now read only for init + scripts. + + depscan.sh now accepts the --svcdir option so that svcdir can now be + specified as the variable is marked readonly in functions.sh. Splash + programs will have to be updated. + 24 Feb 2006; Roy Marples : Misc STYLE and quoting issues fixes in net scripts. diff --git a/ChangeLog.vserver b/ChangeLog.vserver index c499db9..7fd272f 100644 --- a/ChangeLog.vserver +++ b/ChangeLog.vserver @@ -1,6 +1,27 @@ # ChangeLog for Gentoo System Intialization ("rc") scripts # Copyright 1999-2006 Gentoo Foundation; Distributed under the GPLv2 + 09 Mar 2006; Christian Heim : + Merging latest changes to the baselayout-1_12 branch. This merge is based + upon revision 1939. + + ChangeLog | 19 + + ChangeLog.vserver | 21 + + bin/rc-status | 2 + net-scripts/init.d/net.lo | 4 + net-scripts/net.modules.d/iwconfig | 16 + + sbin/depscan.sh | 71 +++--- + sbin/env-update.sh | 10 + sbin/functions.sh | 88 ++++--- + sbin/rc | 26 +- + sbin/rc-daemon.sh | 8 + sbin/rc-help.sh | 10 + sbin/rc-services.sh | 25 +- + sbin/runscript.sh | 211 ++++++++---------- + src/awk/cachedepends.awk | 18 - + src/awk/gendepends.awk | 12 - + 15 files changed, 303 insertions(+), 238 deletions(-) + 27 Feb 2006; Christian Heim : Merging latest changes to the baselayout-1_12 branch. This merge is based upon revision 1928. diff --git a/bin/rc-status b/bin/rc-status index 1cc8572..4f6a29a 100755 --- a/bin/rc-status +++ b/bin/rc-status @@ -31,8 +31,6 @@ runleveldir=/etc/runlevels # grab settings from conf.d/rc source "${svclib}/sh/rc-daemon.sh" -conf="$(add_suffix /etc/conf.d/rc)" -[[ -e ${conf} ]] && source "${conf}" ################################################################################ # Parse command line options # diff --git a/net-scripts/init.d/net.lo b/net-scripts/init.d/net.lo index 332834b..028f8c7 100755 --- a/net-scripts/init.d/net.lo +++ b/net-scripts/init.d/net.lo @@ -16,7 +16,7 @@ depend() { # Load any custom depend functions for the given interface # For example, br0 may need eth0 and eth1 - local iface="${myservice#*.}" + local iface="${SVCNAME#*.}" [[ $(type -t "depend_${iface}") == "function" ]] && depend_${iface} return 0 @@ -953,6 +953,7 @@ link_file() { # Start entry point so that we only have one function # which localises variables and unsets functions start() { + declare -r IFACE="${SVCNAME#*.}" if [[ ${IN_HOTPLUG} == "1" ]] ; then # If we've been called by hotplug, check if we have # a policy for the interface for not starting @@ -988,6 +989,7 @@ start() { # Stop entry point so that we only have one function # which localises variables and unsets functions stop() { + declare -r IFACE="${SVCNAME#*.}" einfo "Stopping ${IFACE}" run "${IFACE}" stop } diff --git a/net-scripts/net.modules.d/iwconfig b/net-scripts/net.modules.d/iwconfig index 9d079c2..34082d4 100644 --- a/net-scripts/net.modules.d/iwconfig +++ b/net-scripts/net.modules.d/iwconfig @@ -335,8 +335,6 @@ iwconfig_associate() { eerror "Unable to change mode to ${mode}" return 1 fi - interface_down "${iface}" - interface_up "${iface}" if [[ ${ESSID} == "any" ]]; then iwconfig "${iface}" ap any 2>/dev/null @@ -371,7 +369,7 @@ iwconfig_associate() { fi # Finally apply the user Config - #iwconfig_user_config "${iface}" "${ESSIDVAR}" + iwconfig_user_config "${iface}" "${ESSIDVAR}" vebegin "Connecting to \"${dessid}\" ${w}" @@ -690,8 +688,13 @@ iwconfig_defaults() { iwconfig "${iface}" txpower auto &>/dev/null iwconfig "${iface}" key [1] off &>/dev/null iwconfig "${iface}" mode managed &>/dev/null - iwconfig "${iface}" essid -- off &>/dev/null iwconfig "${iface}" ap off &>/dev/null + + # According to the iwconfig man page we should be doing + # iwconfig "${iface}" essid -- off &>/dev/null + # instead. However, this borks many drivers - setting essid + # to "" seems to work for all drivers however. + iwconfig "${iface}" essid "" &>/dev/null } # void iwconfig_strip_associated(char *iface) @@ -909,4 +912,9 @@ iwconfig_pre_start() { return 1 } +iwconfig_post_stop() { + interface_exists "${iface}" || return 0 + iwconfig_defaults "${iface}" +} + # vim:ts=4 diff --git a/sbin/depscan.sh b/sbin/depscan.sh index a67b8d7..ed16100 100755 --- a/sbin/depscan.sh +++ b/sbin/depscan.sh @@ -3,68 +3,83 @@ # Distributed under the terms of the GNU General Public License v2 source /sbin/functions.sh - -if [[ $1 == "--debug" ]] ; then +mysvcdir="${svcdir}" +update=false + +while [[ -n $1 ]] ; do + case "$1" in + --debug|-d) + set -x + ;; + --svcdir|-s) + if [[ -z $2 || $2 == -* ]] ; then + eerror "No svcdir specified" + else + shift + mysvcdir="$1" + fi + ;; + --update|-u) + update=true + ;; + esac shift - set -x -fi +done -if [[ ! -d ${svcdir} ]] ; then - if ! mkdir -p -m 0755 "${svcdir}" 2>/dev/null ; then - eerror "Could not create needed directory '${svcdir}'!" +if [[ ! -d ${mysvcdir} ]] ; then + if ! mkdir -p -m 0755 "${mysvcdir}" 2>/dev/null ; then + eerror "Could not create needed directory '${mysvcdir}'!" fi fi for x in softscripts snapshot options daemons \ started starting inactive wasinactive stopping failed \ exclusive exitcodes scheduled ; do - if [[ ! -d "${svcdir}/${x}" ]] ; then - if ! mkdir -p -m 0755 "${svcdir}/${x}" 2>/dev/null ; then - eerror "Could not create needed directory '${svcdir}/${x}'!" + if [[ ! -d "${mysvcdir}/${x}" ]] ; then + if ! mkdir -p -m 0755 "${mysvcdir}/${x}" 2>/dev/null ; then + eerror "Could not create needed directory '${mysvcdir}/${x}'!" fi fi done # Only update if files have actually changed -update=1 - -if [[ $1 == "-u" ]] ; then - update=0 - clock_screw=0 - mtime_test="${svcdir}/mtime-test.$$" +if ! ${update} ; then + clock_screw=false + mtime_test="${mysvcdir}/mtime-test.$$" # If its not there, we have to update, and make sure its present # for next mtime testing - if [[ ! -e "${svcdir}/depcache" ]] ; then - update=1 - touch "${svcdir}/depcache" + if [[ ! -e "${mysvcdir}/depcache" ]] ; then + update=true + touch "${mysvcdir}/depcache" fi touch "${mtime_test}" for config in /etc/conf.d /etc/init.d /etc/rc.conf do - [[ ${update} == 0 ]] && \ - is_older_than "${svcdir}/depcache" "${config}" && update=1 + ! ${update} \ + && is_older_than "${mysvcdir}/depcache" "${config}" \ + && update=true - is_older_than "${mtime_test}" "${config}" && clock_screw=1 + is_older_than "${mtime_test}" "${config}" && clock_screw=true done rm -f "${mtime_test}" - [[ ${clock_screw} == 1 ]] && \ + ${clock_screw} && \ ewarn "Some file in '/etc/{conf.d,init.d}' have Modification time in the future!" shift fi -[[ ${update} == 0 && -e "${svcdir}/deptree" ]] && exit 0 +! ${update} && [[ -e "${mysvcdir}/deptree" ]] && exit 0 ebegin "Caching service dependencies" # Clean out the non volitile directories ... -rm -rf "${svcdir}"/dep{cache,tree} "${svcdir}"/{broken,snapshot}/* +rm -rf "${mysvcdir}"/dep{cache,tree} "${mysvcdir}"/{broken,snapshot}/* retval=0 -SVCDIR="${svcdir}" +SVCDIR="${mysvcdir}" DEPTYPES="${deptypes}" ORDTYPES="${ordtypes}" @@ -77,14 +92,14 @@ cd /etc/init.d -f /lib/rcscripts/awk/cachedepends.awk || \ retval=1 -bash "${svcdir}/depcache" | \ +bash "${mysvcdir}/depcache" | \ /bin/gawk \ -f /lib/rcscripts/awk/functions.awk \ -f /lib/rcscripts/awk/gendepends.awk || \ retval=1 -touch "${svcdir}"/dep{cache,tree} -chmod 0644 "${svcdir}"/dep{cache,tree} +touch "${mysvcdir}"/dep{cache,tree} +chmod 0644 "${mysvcdir}"/dep{cache,tree} eend ${retval} "Failed to cache service dependencies" diff --git a/sbin/env-update.sh b/sbin/env-update.sh index 533e989..e31d8de 100755 --- a/sbin/env-update.sh +++ b/sbin/env-update.sh @@ -4,8 +4,7 @@ source /sbin/functions.sh || exit 1 -if [ "${EUID}" -ne 0 ] -then +if [[ ${EUID} != "0" ]] ; then eerror "$0: must be root." exit 1 fi @@ -23,14 +22,12 @@ note: export SVCDIR="${svcdir}" # Only update if files have actually changed -if [ "$1" == "-u" ] -then +if [[ $1 == "-u" ]] ; then is_older_than "${svcdir}/envcache" /etc/env.d && exit 0 shift fi -if [ "$#" -ne 0 ] -then +if [[ $# != "0" ]] ; then usage else /bin/gawk \ @@ -38,5 +35,4 @@ else -f /lib/rcscripts/awk/genenviron.awk fi - # vim:ts=4 diff --git a/sbin/functions.sh b/sbin/functions.sh index d02a902..fd8c953 100644 --- a/sbin/functions.sh +++ b/sbin/functions.sh @@ -4,14 +4,14 @@ RC_GOT_FUNCTIONS="yes" # Override defaults with user settings ... -[ -f /etc/conf.d/rc ] && source /etc/conf.d/rc +[[ -f /etc/conf.d/rc ]] && source /etc/conf.d/rc # daemontools dir SVCDIR="/var/lib/supervise" # Check /etc/conf.d/rc for a description of these ... -svclib="/lib/rcscripts" -svcdir=${svcdir:-/var/lib/init.d} +declare -r svclib="/lib/rcscripts" +declare -r svcdir="${svcdir:-/var/lib/init.d}" # Different types of dependencies deptypes="need use" @@ -23,21 +23,21 @@ ordtypes="before after" # # Dont output to stdout? -RC_QUIET_STDOUT=${RC_QUIET_STDOUT:-no} -RC_VERBOSE=${RC_VERBOSE:-no} +RC_QUIET_STDOUT="${RC_QUIET_STDOUT:-no}" +RC_VERBOSE="${RC_VERBOSE:-no}" # Should we use color? -RC_NOCOLOR=${RC_NOCOLOR:-no} +RC_NOCOLOR="${RC_NOCOLOR:-no}" # Can the terminal handle endcols? RC_ENDCOL="yes" # # Default values for rc system # -RC_TTY_NUMBER=${RC_TTY_NUMBER:-0} -RC_PARALLEL_STARTUP=${RC_PARALLEL_STARTUP:-no} -RC_NET_STRICT_CHECKING=${RC_NET_STRICT_CHECKING:-none} -RC_DOWN_INTERFACE=${RC_DOWN_INTERFACE:-yes} +RC_TTY_NUMBER="${RC_TTY_NUMBER:-0}" +RC_PARALLEL_STARTUP="${RC_PARALLEL_STARTUP:-no}" +RC_NET_STRICT_CHECKING="${RC_NET_STRICT_CHECKING:-none}" +RC_DOWN_INTERFACE="${RC_DOWN_INTERFACE:-yes}" # # Default values for e-message indentation and dots @@ -119,9 +119,9 @@ get_libdir() { if [[ -n ${CONF_LIBDIR_OVERRIDE} ]] ; then CONF_LIBDIR="${CONF_LIBDIR_OVERRIDE}" elif [[ -x /usr/bin/portageq ]] ; then - CONF_LIBDIR=$(/usr/bin/portageq envvar CONF_LIBDIR) + CONF_LIBDIR="$(/usr/bin/portageq envvar CONF_LIBDIR)" fi - echo ${CONF_LIBDIR:=lib} + echo "${CONF_LIBDIR:=lib}" } # void esyslog(char* priority, char* tag, char* message) @@ -241,12 +241,12 @@ eerror() { # show a message indicating the start of a process # ebegin() { - local msg="$*" dots spaces=${RC_DOT_PATTERN//?/ } + local msg="$*" dots spaces="${RC_DOT_PATTERN//?/ }" [[ ${RC_QUIET_STDOUT} == "yes" ]] && return 0 if [[ -n ${RC_DOT_PATTERN} ]] ; then - dots=$(printf "%$(( COLS - 3 - ${#RC_INDENTATION} - ${#msg} - 7 ))s" '') - dots=${dots//${spaces}/${RC_DOT_PATTERN}} + dots="$(printf "%$((COLS - 3 - ${#RC_INDENTATION} - ${#msg} - 7))s" '')" + dots="${dots//${spaces}/${RC_DOT_PATTERN}}" msg="${msg}${dots}" else msg="${msg} ..." @@ -254,7 +254,7 @@ ebegin() { einfon "${msg}" [[ ${RC_ENDCOL} == "yes" ]] && echo - LAST_E_LEN=$(( 3 + ${#RC_INDENTATION} + ${#msg} )) + LAST_E_LEN="$(( 3 + ${#RC_INDENTATION} + ${#msg} ))" LAST_E_CMD="ebegin" return 0 } @@ -268,7 +268,7 @@ ebegin() { # script. # _eend() { - local retval=${1:-0} efunc=${2:-eerror} msg + local retval="${1:-0}" efunc="${2:-eerror}" msg shift 2 if [[ ${retval} == "0" ]] ; then @@ -297,10 +297,10 @@ _eend() { # if error, show errstr via eerror # eend() { - local retval=${1:-0} + local retval="${1:-0}" shift - _eend ${retval} eerror "$*" + _eend "${retval}" eerror "$*" LAST_E_CMD="eend" return ${retval} @@ -312,10 +312,10 @@ eend() { # if error, show errstr via ewarn # ewend() { - local retval=${1:-0} + local retval="${1:-0}" shift - _eend ${retval} ewarn "$*" + _eend "${retval}" ewarn "$*" LAST_E_CMD="ewend" return ${retval} @@ -344,7 +344,7 @@ veend() { KV_major() { [[ -z $1 ]] && return 1 - local KV=$@ + local KV="$@" echo "${KV%%.*}" } @@ -355,8 +355,8 @@ KV_major() { KV_minor() { [[ -z $1 ]] && return 1 - local KV=$@ - KV=${KV#*.} + local KV="$@" + KV="${KV#*.}" echo "${KV%%.*}" } @@ -367,8 +367,8 @@ KV_minor() { KV_micro() { [[ -z $1 ]] && return 1 - local KV=$@ - KV=${KV#*.*.} + local KV="$@" + KV="${KV#*.*.}" echo "${KV%%[^[:digit:]]*}" } @@ -380,10 +380,10 @@ KV_micro() { KV_to_int() { [[ -z $1 ]] && return 1 - local KV_MAJOR=$(KV_major "$1") - local KV_MINOR=$(KV_minor "$1") - local KV_MICRO=$(KV_micro "$1") - local KV_int=$(( KV_MAJOR * 65536 + KV_MINOR * 256 + KV_MICRO )) + local KV_MAJOR="$(KV_major "$1")" + local KV_MINOR="$(KV_minor "$1")" + local KV_MICRO="$(KV_micro "$1")" + local KV_int="$(( KV_MAJOR * 65536 + KV_MINOR * 256 + KV_MICRO ))" # We make version 2.2.0 the minimum version we will handle as # a sanity check ... if its less, we fail ... @@ -405,9 +405,9 @@ KV_to_int() { _RC_GET_KV_CACHE="" get_KV() { [[ -z ${_RC_GET_KV_CACHE} ]] \ - && _RC_GET_KV_CACHE=$(uname -r) + && _RC_GET_KV_CACHE="$(uname -r)" - echo $(KV_to_int "${_RC_GET_KV_CACHE}") + echo "$(KV_to_int "${_RC_GET_KV_CACHE}")" return $? } @@ -470,11 +470,11 @@ save_options() { local myopts="$1" shift - if [[ ! -d "${svcdir}/options/${myservice}" ]] ; then - mkdir -p -m 0755 "${svcdir}/options/${myservice}" + if [[ ! -d "${svcdir}/options/${SVCNAME}" ]] ; then + mkdir -p -m 0755 "${svcdir}/options/${SVCNAME}" fi - echo "$*" > "${svcdir}/options/${myservice}/${myopts}" + echo "$*" > "${svcdir}/options/${SVCNAME}/${myopts}" return 0 } @@ -485,8 +485,8 @@ save_options() { # by calling the save_options function # get_options() { - if [[ -f "${svcdir}/options/${myservice}/$1" ]] ; then - echo "$(< ${svcdir}/options/${myservice}/$1)" + if [[ -f "${svcdir}/options/${SVCNAME}/$1" ]] ; then + echo "$(< ${svcdir}/options/${SVCNAME}/$1)" fi return 0 @@ -507,7 +507,7 @@ add_suffix() { # get_base_ver() { [[ ! -r /etc/gentoo-release ]] && return 0 - local ver=$(/dev/null ) + export CONSOLETYPE="$( /sbin/consoletype 2>/dev/null )" fi if [[ ${CONSOLETYPE} == "serial" ]] ; then RC_NOCOLOR="yes" @@ -699,6 +699,12 @@ if [[ -z ${EBUILD} ]] ; then done setup_defaultlevels + + # If we are not /sbin/rc then ensure that we cannot change level variables + if [[ -n ${BASH_SOURCE} \ + && ${BASH_SOURCE[${#BASH_SOURCE[@]}-1]} != "/sbin/rc" ]] ; then + declare -r BOOTLEVEL DEFAULTLEVEL SOFTLEVEL + fi else setup_defaultlevels # Should we use colors ? @@ -719,8 +725,8 @@ if [[ -n ${EBUILD} && $* == *depend* ]] ; then COLS=80 else # Setup COLS and ENDCOL so eend can line up the [ ok ] - COLS=${COLUMNS:-0} # bash's internal COLUMNS variable - (( COLS == 0 )) && COLS=$(stty size 2>/dev/null | cut -d' ' -f2) + COLS="${COLUMNS:-0}" # bash's internal COLUMNS variable + (( COLS == 0 )) && COLS="$(set -- `stty size 2>/dev/null` ; echo "$2")" (( COLS > 0 )) || (( COLS = 80 )) # width of [ ok ] == 7 fi diff --git a/sbin/rc b/sbin/rc index 6e0cbba..9eb6177 100755 --- a/sbin/rc +++ b/sbin/rc @@ -163,7 +163,7 @@ then check_critical_services # Update the dependency cache - /sbin/depscan.sh -u + /sbin/depscan.sh # Now that the dependency cache are up to date, make sure these # are marked as started ... @@ -304,23 +304,23 @@ get_stop_services() { dep_stop() { local x dep needsme depservice - local myservice=${1##*/} + local service=${1##*/} - service_stopped "${myservice}" && return 0 + service_stopped "${service}" && return 0 # Candidate for zapping ? - [[ ! -L ${svcdir}/softscripts.new/${myservice} ]] || \ + [[ ! -L ${svcdir}/softscripts.new/${service} ]] || \ return 0 # If this is a 'net' service, we do not want to stop it if it was # not in the previous runlevel, and we are not shutting down, # rebooting or going to single runlevel. This is because the user # (or hotplut) might have started it (net.ppp?) ... - if net_service "${myservice}" && \ + if net_service "${service}" && \ [[ ${SOFTLEVEL} != "reboot" && \ ${SOFTLEVEL} != "shutdown" ]] ; then if [[ -z ${OLDSOFTLEVEL} ]] || \ - ! in_runlevel "${myservice}" "${OLDSOFTLEVEL}" + ! in_runlevel "${service}" "${OLDSOFTLEVEL}" then # This service is not in the previous runlevel, so # do not stop it ... @@ -329,14 +329,14 @@ dep_stop() { fi # Should not work for 'use' - if [[ -z $(needsme "${myservice}") ]] ; then + if [[ -z $(needsme "${service}") ]] ; then # Nothing depends on me - stop_service "${myservice}" + stop_service "${service}" else # Something may depend on me needsme=0 - for dep in $(needsme "${myservice}") ; do + for dep in $(needsme "${service}") ; do if [[ -L "${svcdir}/softscripts.new/${dep}" ]] ; then # This dep is valid needsme=1 @@ -345,7 +345,7 @@ dep_stop() { fi done - [[ ${needsme} -eq 0 ]] && stop_service "${myservice}" + [[ ${needsme} -eq 0 ]] && stop_service "${service}" fi } @@ -364,10 +364,10 @@ else is_critical_service() { local x - local myservice=${1##*/} + local service=${1##*/} for x in ${CRITICAL_SERVICES} ${LOGGER_SERVICE} ; do - [[ ${myservice} == "${x}" ]] && return 0 + [[ ${service} == "${x}" ]] && return 0 done return 1 @@ -395,8 +395,6 @@ fi echo "${SOFTLEVEL}" > "${svcdir}/softlevel" if [[ ${SOFTLEVEL} == "reboot" || ${SOFTLEVEL} == "shutdown" ]] ; then - source /sbin/functions.sh - # Clear $svcdir from stale entries, but leave the caches around, as it # should help speed things up a bit rm -rf $(ls -d1 "${svcdir}/"* 2>/dev/null | \ diff --git a/sbin/rc-daemon.sh b/sbin/rc-daemon.sh index 24409ed..9f9cd26 100644 --- a/sbin/rc-daemon.sh +++ b/sbin/rc-daemon.sh @@ -12,13 +12,11 @@ # when we're testing for the daemon to be running. I (Roy Marples) view this # as behaviour by design as start-stop-daemon should not be used to run shell # scripts! -# At the time of writing, the only culprit I know of is courier-imap. -# There may be others! RC_GOT_DAEMON="yes" [[ ${RC_GOT_FUNCTIONS} != "yes" ]] && source /sbin/functions.sh -[[ ${RC_GOT_SERVICES} != "yes" ]] && source "${svclib}/sh/rc-services.sh" +[[ ${RC_GOT_SVCNAMES} != "yes" ]] && source "${svclib}/sh/rc-services.sh" RC_RETRY_KILL="no" RC_RETRY_TIMEOUT=1 @@ -100,7 +98,7 @@ rc_setup_daemon_vars() { # We may want to launch the daemon with a custom command # This is mainly useful for debugging with apps like valgrind, strace - local bash_service="$( bash_variable "${myservice}" )" + local bash_service="$( bash_variable "${SVCNAME}" )" if [[ -n ${RC_DAEMON} ]]; then local -a d=( ${RC_DAEMON} ) if ${stopping}; then @@ -357,7 +355,7 @@ update_service_status() { start-stop-daemon() { local args="$( requote "$@" )" result i local cmd pidfile pid stopping signal nothing=false - local daemonfile="${svcdir}/daemons/${myservice}" + local daemonfile="${svcdir}/daemons/${SVCNAME}" local -a RC_DAEMONS=() RC_PIDFILES=() [[ -e ${daemonfile} ]] && source "${daemonfile}" diff --git a/sbin/rc-help.sh b/sbin/rc-help.sh index a757d87..30a5736 100755 --- a/sbin/rc-help.sh +++ b/sbin/rc-help.sh @@ -20,11 +20,11 @@ if [[ -z ${myscript} ]] ; then fi if [[ -L ${myscript} ]] ; then - myservice=$(readlink "${myscript}") + SERVICE=$(readlink "${myscript}") else - myservice=${myscript} + SERVICE=${myscript} fi -myservice=${myservice##*/} +SERVICE=${SERVICE##*/} if [[ $2 == "help" ]] ; then BE_VERBOSE="yes" @@ -44,7 +44,7 @@ ${GREEN}Gentoo RC-Scripts; ${BLUE}http://www.gentoo.org/${OFF} " fi -echo -e "Usage: ${CYAN}${myservice}${OFF} [ ${GREEN}flags${OFF} ] < ${GREEN}options${OFF} > +echo -e "Usage: ${CYAN}${SERVICE}${OFF} [ ${GREEN}flags${OFF} ] < ${GREEN}options${OFF} > ${CYAN}Normal Options:${OFF}" @@ -221,7 +221,7 @@ echo -e " " fi -echo -e " /etc/conf.d/${myservice}${NL} /etc/rc.conf" +echo -e " /etc/conf.d/${SERVICE}${NL} /etc/rc.conf" if [[ ${BE_VERBOSE} == "yes" ]] ; then echo -e " diff --git a/sbin/rc-services.sh b/sbin/rc-services.sh index 96940d0..fd2bf48 100755 --- a/sbin/rc-services.sh +++ b/sbin/rc-services.sh @@ -2,14 +2,13 @@ # Distributed under the terms of the GNU General Public License v2 # RC Dependency and misc service functions - -RC_GOT_SERVICES="yes" +RC_GOT_SVCNAMES="yes" [[ ${RC_GOT_FUNCTIONS} != "yes" ]] && source /sbin/functions.sh if [[ ${RC_GOT_DEPTREE_INFO} != "yes" ]] ; then # Only try and update if we are root - if [[ ${EUID} == "0" ]] && ! /sbin/depscan.sh -u ; then + if [[ ${EUID} == "0" ]] && ! /sbin/depscan.sh ; then echo eerror "Error running '/sbin/depscan.sh'!" eerror "Please correct any problems above." @@ -141,18 +140,18 @@ check_dependency() { fi # Do we have valid info for 'deptype' ? - eval deps=\"\$\{rc_$1\}\" - [[ -z ${deps} ]] && return 1 + deps="rc_$1" + [[ -z ${!deps} ]] && return 1 if [[ $2 == "-t" && -n $4 ]]; then # Check if 'service1' have 'deptype' dependency on 'service2' - for x in ${deps} ; do + for x in ${!deps} ; do [[ ${x} == "$4" ]] && return 0 done return 1 else # Just list all services that 'service1' have 'deptype' dependency on. - echo "${deps}" + echo "${!deps}" return 0 fi } @@ -504,7 +503,7 @@ mark_service_stopped() { rm -Rf "${svcdir}/daemons/$1" "${svcdir}/starting/$1" \ "${svcdir}/started/$1" "${svcdir}/inactive/$1" \ "${svcdir}/wasinactive/$1" "${svcdir}/stopping/$1" \ - "${svcdir}/scheduled/$1" + "${svcdir}/scheduled/$1" "${svcdir}/options/$1" return 0 } @@ -716,10 +715,10 @@ trace_dependencies() { if [[ $1 == -* ]]; then deptype="${1/-/}" - if net_service "${myservice}" ; then - services=( "net" "${myservice}" ) + if net_service "${SVCNAME}" ; then + services=( "net" "${SVCNAME}" ) else - services=( "${myservice}" ) + services=( "${SVCNAME}" ) fi fi @@ -794,10 +793,10 @@ trace_dependencies() { if [[ -n ${deptype} ]] ; then # If deptype is set, we do not want the name of this service x=" ${services[@]} " - services=( ${x// ${myservice} / } ) + services=( ${x// ${SVCNAME} / } ) # If its a net service, do not include "net" - if net_service "${myservice}" ; then + if net_service "${SVCNAME}" ; then x=" ${services[@]} " sorted=( ${services// net / } ) fi diff --git a/sbin/runscript.sh b/sbin/runscript.sh index a4357aa..d43fae8 100755 --- a/sbin/runscript.sh +++ b/sbin/runscript.sh @@ -6,29 +6,31 @@ [[ ${RC_GOT_FUNCTIONS} != "yes" ]] && source /sbin/functions.sh # User must be root to run most script stuff (except status) -if [[ ${EUID} != 0 ]] && ! [[ $2 == "status" && $# -eq 2 ]] ; then +if [[ ${EUID} != "0" ]] && ! [[ $2 == "status" && $# -eq 2 ]] ; then eerror "$0: must be root to run init scripts" exit 1 fi myscript="$1" if [[ -L $1 && ! -L "/etc/init.d/${1##*/}" ]] ; then - myservice="$(readlink "$1")" + SVCNAME="$(readlink "$1")" else - myservice="$1" + SVCNAME="$1" fi -myservice="${myservice##*/}" -export SVCNAME="${myservice}" +declare -r SVCNAME="${SVCNAME##*/}" +export SVCNAME +# Support deprecated myservice variable +myservice="${SVCNAME}" # Stop init scripts from working until sysinit completes if [[ -e /dev/.rcsysinit ]] ; then - eerror "ERROR: cannot run ${myservice} until sysinit completes" + eerror "ERROR: cannot run ${SVCNAME} until sysinit completes" exit 1 fi svc_trap() { - trap 'eerror "ERROR: ${myservice} caught an interrupt"; exit 1' \ + trap 'eerror "ERROR: ${SVCNAME} caught an interrupt"; exit 1' \ INT QUIT TSTP } @@ -40,22 +42,19 @@ svcpause="no" svcrestart="no" # Functions to handle dependencies and services -[[ ${RC_GOT_SERVICES} != "yes" ]] && source "${svclib}/sh/rc-services.sh" +[[ ${RC_GOT_SVCNAMES} != "yes" ]] && source "${svclib}/sh/rc-services.sh" # Functions to control daemons [[ ${RC_GOT_DAEMON} != "yes" ]] && source "${svclib}/sh/rc-daemon.sh" -# Set $IFACE to the name of the network interface if it is a 'net.*' script -if [[ ${myservice%%.*} == "net" && ${myservice#*.} != "${myservice}" ]] ; then - IFACE="${myservice#*.}" +if [[ ${SVCNAME%%.*} == "net" && ${SVCNAME#*.} != "${SVCNAME}" ]] ; then NETSERVICE="yes" else - IFACE= - NETSERVICE= + NETSERVICE="no" fi # Source configuration files. # (1) Source /etc/conf.d/net if it is a net.* service -# (2) Source /etc/conf.d/${myservice} to get initscript-specific +# (2) Source /etc/conf.d/${SVCNAME} to get initscript-specific # configuration (if it exists). # (3) Source /etc/rc.conf to pick up potentially overriding # configuration, if the system administrator chose to put it @@ -64,7 +63,7 @@ if [[ ${NETSERVICE} == "yes" ]] ; then conf="$(add_suffix /etc/conf.d/net)" [[ -e ${conf} ]] && source "${conf}" fi -conf="$(add_suffix "/etc/conf.d/${myservice}")" +conf="$(add_suffix "/etc/conf.d/${SVCNAME}")" [[ -e ${conf} ]] && source "${conf}" conf="$(add_suffix /etc/rc.conf)" [[ -e ${conf} ]] && source "${conf}" @@ -75,28 +74,28 @@ mylevel="${SOFTLEVEL}" && mylevel="${DEFAULTLEVEL}" # Call svc_quit if we abort AND we have obtained a lock -service_started "${myservice}" +service_started "${SVCNAME}" svcstarted="$?" -service_inactive "${myservice}" +service_inactive "${SVCNAME}" svcinactive="$?" svc_quit() { - eerror "ERROR: ${myservice} caught an interrupt" - if service_inactive "${myservice}" || [[ ${svcinactive} == 0 ]] ; then - mark_service_inactive "${myservice}" + eerror "ERROR: ${SVCNAME} caught an interrupt" + if service_inactive "${SVCNAME}" || [[ ${svcinactive} == 0 ]] ; then + mark_service_inactive "${SVCNAME}" elif [[ ${svcstarted} == 0 ]] ; then - mark_service_started "${myservice}" + mark_service_started "${SVCNAME}" else - mark_service_stopped "${myservice}" + mark_service_stopped "${SVCNAME}" fi exit 1 } usage() { local IFS="|" - myline="Usage: ${myservice} { $* " + myline="Usage: ${SVCNAME} { $* " echo eerror "${myline}}" - eerror " ${myservice} without arguments for full help" + eerror " ${SVCNAME} without arguments for full help" } stop() { @@ -105,7 +104,7 @@ stop() { } start() { - eerror "ERROR: ${myservice} does not have a start function." + eerror "ERROR: ${SVCNAME} does not have a start function." # Return failure so the symlink doesn't get created return 1 } @@ -129,19 +128,19 @@ svc_schedule_start() { } svc_start_scheduled() { - [[ ! -d "${svcdir}/scheduled/${myservice}" ]] && return + [[ ! -d "${svcdir}/scheduled/${SVCNAME}" ]] && return local x= services= - for x in $(dolisting "${svcdir}/scheduled/${myservice}/") ; do + for x in $(dolisting "${svcdir}/scheduled/${SVCNAME}/") ; do services="${services} ${x##*/}" done for x in ${services} ; do service_stopped "${x}" && start_service "${x}" - rm -f "${svcdir}/scheduled/${myservice}/${x}" + rm -f "${svcdir}/scheduled/${SVCNAME}/${x}" done - rmdir "${svcdir}/scheduled/${myservice}" + rmdir "${svcdir}/scheduled/${SVCNAME}" } svc_stop() { @@ -149,24 +148,24 @@ svc_stop() { local -a servicelist=() # Do not try to stop if it had already failed to do so - if is_runlevel_stop && service_failed "${myservice}" ; then + if is_runlevel_stop && service_failed "${SVCNAME}" ; then return 1 - elif service_stopped "${myservice}" ; then - ewarn "WARNING: ${myservice} has not yet been started." + elif service_stopped "${SVCNAME}" ; then + ewarn "WARNING: ${SVCNAME} has not yet been started." return 0 fi - if ! mark_service_stopping "${myservice}" ; then - eerror "ERROR: ${myservice} is already stopping." + if ! mark_service_stopping "${SVCNAME}" ; then + eerror "ERROR: ${SVCNAME} is already stopping." return 1 fi # Ensure that we clean up if we abort for any reason trap "svc_quit" INT QUIT TSTP - mark_service_starting "${myservice}" - service_message "Service ${myservice} stopping" + mark_service_starting "${SVCNAME}" + service_message "Service ${SVCNAME} stopping" - if in_runlevel "${myservice}" "${BOOTLEVEL}" && \ + if in_runlevel "${SVCNAME}" "${BOOTLEVEL}" && \ [[ ${SOFTLEVEL} != "reboot" && ${SOFTLEVEL} != "shutdown" ]] ; then ewarn "WARNING: you are stopping a boot service." fi @@ -174,15 +173,15 @@ svc_stop() { if [[ ${svcpause} != "yes" ]] ; then if [[ ${NETSERVICE} == "yes" ]] ; then # A net.* service - if in_runlevel "${myservice}" "${BOOTLEVEL}" || \ - in_runlevel "${myservice}" "${mylevel}" ; then + if in_runlevel "${SVCNAME}" "${BOOTLEVEL}" || \ + in_runlevel "${SVCNAME}" "${mylevel}" ; then # Only worry about net.* services if this is the last one # running or if RC_NET_STRICT_CHECKING is set ... ! is_net_up && mydeps="net" fi - mydeps="${mydeps} ${myservice}" + mydeps="${mydeps} ${SVCNAME}" else - mydeps="${myservice}" + mydeps="${SVCNAME}" fi fi @@ -217,7 +216,7 @@ svc_stop() { if [[ ${retval} != 0 ]] ; then eerror "ERROR: problems stopping dependent services." - eerror " ${myservice} is still up." + eerror " ${SVCNAME} is still up." else # Now that deps are stopped, stop our service ( @@ -236,7 +235,7 @@ svc_stop() { # If a service has been marked inactive, exit now as something # may attempt to start it again later - if service_inactive "${myservice}" ; then + if service_inactive "${SVCNAME}" ; then svcinactive=0 return 0 fi @@ -245,28 +244,28 @@ svc_stop() { if [[ ${retval} != 0 ]] ; then # Did we fail to stop? create symlink to stop multible attempts at # runlevel change. Note this is only used at runlevel change ... - is_runlevel_stop && mark_service_failed "${myservice}" + is_runlevel_stop && mark_service_failed "${SVCNAME}" # If we are halting the system, do it as cleanly as possible if [[ ${SOFTLEVEL} == "reboot" || ${SOFTLEVEL} == "shutdown" ]] ; then - mark_service_stopped "${myservice}" + mark_service_stopped "${SVCNAME}" else if [[ ${svcinactive} == 0 ]] ; then - mark_service_inactive "${myservice}" + mark_service_inactive "${SVCNAME}" else - mark_service_started "${myservice}" + mark_service_started "${SVCNAME}" fi fi - service_message "eerror" "ERROR: ${myservice} failed to stop" + service_message "eerror" "ERROR: ${SVCNAME} failed to stop" else svcstarted=1 - if service_inactive "${myservice}" ; then + if service_inactive "${SVCNAME}" ; then svcinactive=0 else - mark_service_stopped "${myservice}" + mark_service_stopped "${SVCNAME}" fi - service_message "Stopped service ${myservice}" + service_message "Stopped service ${SVCNAME}" fi # Reset the trap @@ -279,23 +278,23 @@ svc_start() { local x= y= retval=0 startfail= startinactive= # Do not try to start if i have done so already on runlevel change - if is_runlevel_start && service_failed "${myservice}" ; then + if is_runlevel_start && service_failed "${SVCNAME}" ; then return 1 - elif service_started "${myservice}" ; then - ewarn "WARNING: ${myservice} has already been started." + elif service_started "${SVCNAME}" ; then + ewarn "WARNING: ${SVCNAME} has already been started." return 0 - elif service_inactive "${myservice}" ; then + elif service_inactive "${SVCNAME}" ; then if [[ ${IN_BACKGROUND} != "true" ]] ; then - ewarn "WARNING: ${myservice} has already been started." + ewarn "WARNING: ${SVCNAME} has already been started." return 0 fi fi - if ! mark_service_starting "${myservice}" ; then - if service_stopping "${myservice}" ; then - eerror "ERROR: ${myservice} is already stopping." + if ! mark_service_starting "${SVCNAME}" ; then + if service_stopping "${SVCNAME}" ; then + eerror "ERROR: ${SVCNAME} is already stopping." else - eerror "ERROR: ${myservice} is already starting." + eerror "ERROR: ${SVCNAME} is already starting." fi return 1 fi @@ -303,13 +302,13 @@ svc_start() { # Ensure that we clean up if we abort for any reason trap "svc_quit" INT QUIT TSTP - service_message "Service ${myservice} starting" + service_message "Service ${SVCNAME} starting" # Save the IN_BACKGROUND var as we need to clear it for starting depends local ib_save="${IN_BACKGROUND}" unset IN_BACKGROUND - local startupservices="$(ineed "${myservice}") $(valid_iuse "${myservice}")" + local startupservices="$(ineed "${SVCNAME}") $(valid_iuse "${SVCNAME}")" local netservices= for x in $(dolisting "/etc/runlevels/${BOOTLEVEL}/net.*") \ $(dolisting "/etc/runlevels/${mylevel}/net.*") ; do @@ -334,7 +333,7 @@ svc_start() { # We also wait for any services we're after to finish incase they # have a "before" dep but we don't dep on them. if is_runlevel_start ; then - startupservices="${startupservices} $(valid_iafter "${myservice}")" + startupservices="${startupservices} $(valid_iafter "${SVCNAME}")" fi if [[ " ${startupservices} " == *" net "* ]] ; then @@ -349,12 +348,12 @@ svc_start() { wait_service "${x}" if ! service_started "${x}" ; then # A 'need' dependency is critical for startup - if ineed -t "${myservice}" "${x}" >/dev/null \ - || net_service "${x}" && ineed -t "${myservice}" net \ + if ineed -t "${SVCNAME}" "${x}" >/dev/null \ + || net_service "${x}" && ineed -t "${SVCNAME}" net \ && ! is_net_up ; then if service_inactive "${x}" || service_wasinactive "${x}" || \ [[ -n $(ls "${svcdir}"/scheduled/*/"${x}" 2>/dev/null) ]] ; then - svc_schedule_start "${x}" "${myservice}" + svc_schedule_start "${x}" "${SVCNAME}" startinactive="${x}" else startfail="${x}" @@ -366,15 +365,15 @@ svc_start() { if [[ -n ${startfail} ]] ; then eerror "ERROR: Problem starting needed service ${startfail}" - eerror " ${myservice} was not started." + eerror " ${SVCNAME} was not started." retval=1 elif [[ -n ${startinactive} ]] ; then - ewarn "WARNING: ${myservice} is scheduled to start when ${startinactive} has started." + ewarn "WARNING: ${SVCNAME} is scheduled to start when ${startinactive} has started." retval=1 - elif broken "${myservice}" ; then + elif broken "${SVCNAME}" ; then eerror "ERROR: Some services needed are missing. Run" - eerror " './${myservice} broken' for a list of those" - eerror " services. ${myservice} was not started." + eerror " './${SVCNAME} broken' for a list of those" + eerror " services. ${SVCNAME} was not started." retval=1 else IN_BACKGROUND="${ib_save}" @@ -399,28 +398,28 @@ svc_start() { # If a service has been marked inactive, exit now as something # may attempt to start it again later - if service_inactive "${myservice}" ; then + if service_inactive "${SVCNAME}" ; then svcinactive=0 - service_message "ewarn" "WARNING: ${myservice} has started but is inactive" + service_message "ewarn" "WARNING: ${SVCNAME} has started but is inactive" return 1 fi fi if [[ ${retval} != 0 ]] ; then if [[ ${svcinactive} == 0 ]] ; then - mark_service_inactive "${myservice}" + mark_service_inactive "${SVCNAME}" else - mark_service_stopped "${myservice}" + mark_service_stopped "${SVCNAME}" fi if [[ -z ${startinactive} ]] ; then - is_runlevel_start && mark_service_failed "${myservice}" - service_message "eerror" "ERROR: ${myservice} failed to start" + is_runlevel_start && mark_service_failed "${SVCNAME}" + service_message "eerror" "ERROR: ${SVCNAME} failed to start" fi else svcstarted=0 - mark_service_started "${myservice}" - service_message "Service ${myservice} started" + mark_service_started "${SVCNAME}" + service_message "Service ${SVCNAME} started" fi # Reset the trap @@ -430,7 +429,7 @@ svc_start() { } svc_restart() { - if ! service_stopped "${myservice}" ; then + if ! service_stopped "${SVCNAME}" ; then svc_stop || return "$?" fi svc_start @@ -446,18 +445,18 @@ svc_status() { # If we are effectively root, check to see if required daemons are running # and update our status accordingly - [[ ${EUID} == 0 ]] && update_service_status "${myservice}" + [[ ${EUID} == 0 ]] && update_service_status "${SVCNAME}" - if service_stopping "${myservice}" ; then + if service_stopping "${SVCNAME}" ; then efunc="eerror" state="stopping" - elif service_starting "${myservice}" ; then + elif service_starting "${SVCNAME}" ; then efunc="einfo" state="starting" - elif service_inactive "${myservice}" ; then + elif service_inactive "${SVCNAME}" ; then efunc="ewarn" state="inactive" - elif service_started "${myservice}" ; then + elif service_started "${SVCNAME}" ; then efunc="einfo" state="started" else @@ -539,8 +538,8 @@ retval=0 for arg in $* ; do case "${arg}" in stop) - if [[ -e "${svcdir}/scheduled/${myservice}" ]] ; then - rm -Rf "${svcdir}/scheduled/${myservice}" + if [[ -e "${svcdir}/scheduled/${SVCNAME}" ]] ; then + rm -Rf "${svcdir}/scheduled/${SVCNAME}" fi # Stoped from the background - treat this as a restart so that @@ -549,7 +548,7 @@ for arg in $* ; do rm -rf "${svcdir}/snapshot/$$" mkdir -p "${svcdir}/snapshot/$$" cp -pP "${svcdir}"/started/* "${svcdir}/snapshot/$$/" - rm -f "${svcdir}/snapshot/$$/${myservice}" + rm -f "${svcdir}/snapshot/$$/${SVCNAME}" fi svc_stop @@ -558,18 +557,18 @@ for arg in $* ; do if [[ ${IN_BACKGROUND} == "true" ]] ; then for x in $(dolisting "${svcdir}/snapshot/$$/") ; do if service_stopped "${x##*/}" ; then - svc_schedule_start "${myservice}" "${x##*/}" + svc_schedule_start "${SVCNAME}" "${x##*/}" fi done else - rm -f "${svcdir}"/scheduled/*/"${myservice}" + rm -f "${svcdir}"/scheduled/*/"${SVCNAME}" fi ;; start) svc_start retval="$?" - service_started "${myservice}" && svc_start_scheduled + service_started "${SVCNAME}" && svc_start_scheduled ;; needsme|ineed|usesme|iuse|broken) trace_dependencies "-${arg}" @@ -579,8 +578,8 @@ for arg in $* ; do retval="$?" ;; zap) - einfo "Manually resetting ${myservice} to stopped state." - mark_service_stopped "${myservice}" + einfo "Manually resetting ${SVCNAME} to stopped state." + mark_service_stopped "${SVCNAME}" ;; restart) svcrestart="yes" @@ -593,17 +592,17 @@ for arg in $* ; do rm -rf "${svcdir}/snapshot/$$" mkdir -p "${svcdir}/snapshot/$$" cp -pP "${svcdir}"/started/* "${svcdir}/snapshot/$$/" - rm -f "${svcdir}/snapshot/$$/${myservice}" + rm -f "${svcdir}/snapshot/$$/${SVCNAME}" # Simple way to try and detect if the service use svc_{start,stop} # to restart if it have a custom restart() funtion. - if [[ -n $(egrep '^[[:space:]]*restart[[:space:]]*()' "/etc/init.d/${myservice}") ]] ; then - if [[ -z $(egrep 'svc_stop' "/etc/init.d/${myservice}") || \ - -z $(egrep 'svc_start' "/etc/init.d/${myservice}") ]] ; then + if [[ -n $(egrep '^[[:space:]]*restart[[:space:]]*()' "/etc/init.d/${SVCNAME}") ]] ; then + if [[ -z $(egrep 'svc_stop' "/etc/init.d/${SVCNAME}") || \ + -z $(egrep 'svc_start' "/etc/init.d/${SVCNAME}") ]] ; then echo ewarn "Please use 'svc_stop; svc_start' and not 'stop; start' to" ewarn "restart the service in its custom 'restart()' function." - ewarn "Run ${myservice} without arguments for more info." + ewarn "Run ${SVCNAME} without arguments for more info." echo svc_restart else @@ -614,24 +613,24 @@ for arg in $* ; do fi retval="$?" - [[ -e "${svcdir}/scheduled/${myservice}" ]] \ - && rm -Rf "${svcdir}/scheduled/${myservice}" + [[ -e "${svcdir}/scheduled/${SVCNAME}" ]] \ + && rm -Rf "${svcdir}/scheduled/${SVCNAME}" # Restart dependencies as well for x in $(dolisting "${svcdir}/snapshot/$$/") ; do if service_stopped "${x##*/}" ; then - if service_inactive "${myservice}" \ - || service_wasinactive "${myservice}" ; then - svc_schedule_start "${myservice}" "${x##*/}" - ewarn "WARNING: ${x##*/} is scheduled to start when ${myservice} has started." - elif service_started "${myservice}" ; then + if service_inactive "${SVCNAME}" \ + || service_wasinactive "${SVCNAME}" ; then + svc_schedule_start "${SVCNAME}" "${x##*/}" + ewarn "WARNING: ${x##*/} is scheduled to start when ${SVCNAME} has started." + elif service_started "${SVCNAME}" ; then start_service "${x##*/}" fi fi done rm -rf "${svcdir}/snapshot/$$" - service_started "${myservice}" && svc_start_scheduled + service_started "${SVCNAME}" && svc_start_scheduled # Wait for services to come up [[ ${RC_PARALLEL_STARTUP} == "yes" ]] && wait diff --git a/src/awk/cachedepends.awk b/src/awk/cachedepends.awk index 017e231..46945e9 100644 --- a/src/awk/cachedepends.awk +++ b/src/awk/cachedepends.awk @@ -30,9 +30,13 @@ function print_start() { function print_header1(mtime) { print "#*** " MYFILENAME " ***" >> TMPCACHE print "" >> TMPCACHE - print "myservice=\"" MYFILENAME "\"" >> TMPCACHE - print "myservice=\"${myservice##*/}\"" >> TMPCACHE - print "echo \"RCSCRIPT ${myservice}\"" >> TMPCACHE + print "SVCNAME=\"" MYFILENAME "\"" >> TMPCACHE + print "SVCNAME=\"${SVCNAME##*/}\"" >> TMPCACHE + + # Support deprected myservice variable + print "myservice=\"${SVCNAME}\"" >> TMPCACHE + + print "echo \"RCSCRIPT ${SVCNAME}\"" >> TMPCACHE print "" >> TMPCACHE print "echo \"MTIME " mtime "\"" >> TMPCACHE print "" >> TMPCACHE @@ -42,11 +46,11 @@ function print_header2(mtime) { print "(" >> TMPCACHE print " # Get settings for rc-script ..." >> TMPCACHE print "" >> TMPCACHE - print " [ -e \"/etc/conf.d/${myservice}\" ] && source \"/etc/conf.d/${myservice}\"" >> TMPCACHE - print "" >> TMPCACHE print " [ -e /etc/conf.d/net ] && \\" >> TMPCACHE - print " [ \"${myservice%%.*}\" = \"net\" ] && \\" >> TMPCACHE - print " [ \"${myservice##*.}\" != \"${myservice}\" ] && source /etc/conf.d/net" >> TMPCACHE + print " [ \"${SVCNAME%%.*}\" = \"net\" ] && \\" >> TMPCACHE + print " [ \"${SVCNAME##*.}\" != \"${SVCNAME}\" ] && source /etc/conf.d/net" >> TMPCACHE + print "" >> TMPCACHE + print " [ -e \"/etc/conf.d/${SVCNAME}\" ] && source \"/etc/conf.d/${SVCNAME}\"" >> TMPCACHE print "" >> TMPCACHE print " [ -e /etc/rc.conf ] && source /etc/rc.conf" >> TMPCACHE print "" >> TMPCACHE diff --git a/src/awk/gendepends.awk b/src/awk/gendepends.awk index c4073b4..d092ccb 100644 --- a/src/awk/gendepends.awk +++ b/src/awk/gendepends.awk @@ -504,8 +504,8 @@ END { } for (x = TYPES_MIN; x <= TYPES_MAX; x++) - print "rc_type_" TYPE_NAMES[x] "=" x >> (CACHEDTREE) - print "rc_index_scale=" (TYPES_MAX + 1) >> (CACHEDTREE) + print "declare -r rc_type_" TYPE_NAMES[x] "=" x >> (CACHEDTREE) + print "declare -r rc_index_scale=" (TYPES_MAX + 1) >> (CACHEDTREE) print "" >> (CACHEDTREE) print "declare -a RC_DEPEND_TREE" >> (CACHEDTREE) print "" >> (CACHEDTREE) @@ -542,15 +542,17 @@ END { print "" >> (CACHEDTREE) } + # Ensure that no-one changes our tree + print "declare -r RC_DEPEND_TREE" >> (CACHEDTREE) # Do not export these, as we want them local - print "RC_GOT_DEPTREE_INFO=\"yes\"" >> (CACHEDTREE) + print "declare -r RC_GOT_DEPTREE_INFO=\"yes\"" >> (CACHEDTREE) print "" >> (CACHEDTREE) if (check_provide("logger")) - print "LOGGER_SERVICE=\"" get_provide("logger") "\"" >> (CACHEDTREE) + print "declare -r LOGGER_SERVICE=\"" get_provide("logger") "\"" >> (CACHEDTREE) else - print "LOGGER_SERVICE=" >> (CACHEDTREE) + print "declare -r LOGGER_SERVICE=" >> (CACHEDTREE) close(CACHEDTREE) -- cgit v1.2.3-65-gdbad