diff --git a/init.d.BSD/moused.in b/init.d.BSD/moused.in index c36110de..a0e97cdf 100644 --- a/init.d.BSD/moused.in +++ b/init.d.BSD/moused.in @@ -2,7 +2,7 @@ # Copyright 2007-2008 Roy Marples # All rights reserved. Released under the 2-clause BSD license. -mouse=${SVCNAME##*.} +mouse=${RC_SVCNAME##*.} if [ -n "${name}" -a "${mouse}" != "moused" ]; then moused_device=/dev/"${mouse}" pidfile=/var/run/moused-"${mouse}".pid diff --git a/init.d.misc/dnsmasq.in b/init.d.misc/dnsmasq.in index da7b5fb6..02e146c1 100644 --- a/init.d.misc/dnsmasq.in +++ b/init.d.misc/dnsmasq.in @@ -18,7 +18,7 @@ depend() reload() { - ebegin "Reloading ${SVCNAME}" + ebegin "Reloading ${RC_SVCNAME}" start-stop-daemon --signal SIGHUP --pidfile "${pidfile}" eend $? } diff --git a/init.d.misc/openvpn.in b/init.d.misc/openvpn.in index 9e55f42b..4f60b83a 100644 --- a/init.d.misc/openvpn.in +++ b/init.d.misc/openvpn.in @@ -2,12 +2,12 @@ # Copyright 2007-2008 Roy Marples # All rights reserved. Released under the 2-clause BSD license. -vpn=${SVCNAME#*.} +vpn=${RC_SVCNAME#*.} name="OpenVPN" [ "${vpn}" != "openvpn" ] && name="${name} (${vpn})" command=@PKG_PREFIX@/sbin/openvpn -pidfile=@VARBASE@/run/"${SVCNAME}".pid +pidfile=@VARBASE@/run/"${RC_SVCNAME}".pid openvpn_dir=${openvpn_dir:-@PKG_PREFIX@/etc/openvpn} openvpn_config=${openvpn_config:-${openvpn_dir}/${vpn}.conf} command_args="${openvpn_args} --daemon --config ${openvpn_config} --writepid ${pidfile}" diff --git a/man/runscript.8 b/man/runscript.8 index 7aaf9646..6f3bd439 100644 --- a/man/runscript.8 +++ b/man/runscript.8 @@ -22,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd Feb 22, 2008 +.Dd Mar 19, 2008 .Dt RUNSCRIPT 8 SMM .Os OpenRC .Sh NAME @@ -276,7 +276,7 @@ matches YES, TRUE, ON or 1 regardless of case then we return 0, otherwise 1. .Nm sets the following environment variables for use in the service scripts: .Bl -tag -width "RC_DEFAULTLEVEL" -.It Va SVCNAME +.It Va RC_SVCNAME Name of the service. .It Va RC_RUNLEVEL Current runlevel that rc is in. @@ -295,11 +295,11 @@ The result of `uname -s`. Configuration files, relative to the location of the service. If a file ending with .${RC_RUNLEVEL} exists then we use that instead. .Bl -ohang -.It Pa ../conf.d/${SVCNAME%%.*} +.It Pa ../conf.d/${RC_SVCNAME%%.*} mulitplexed configuration file. -Example: if ${SVCNAME} is net.eth1 then look for +Example: if ${RC_SVCNAME} is net.eth1 then look for .Pa ../conf.d/net . -.It Pa ../conf.d/${SVCNAME} +.It Pa ../conf.d/${RC_SVCNAME} service configuration file. .It Pa /etc/rc.conf host configuration file. diff --git a/net.Linux/tuntap.sh b/net.Linux/tuntap.sh index 142c0f8f..3174d812 100644 --- a/net.Linux/tuntap.sh +++ b/net.Linux/tuntap.sh @@ -10,7 +10,7 @@ _config_vars="$_config_vars tunctl" _is_tuntap() { - [ -n "$(export SVCNAME="net.${IFACE}"; service_get_value tuntap)" ] + [ -n "$(export RC_SVCNAME="net.${IFACE}"; service_get_value tuntap)" ] } tuntap_pre_start() diff --git a/net.Linux/vlan.sh b/net.Linux/vlan.sh index 2883f3b6..7d77aae8 100644 --- a/net.Linux/vlan.sh +++ b/net.Linux/vlan.sh @@ -91,7 +91,7 @@ vlan_post_start() /proc/net/vlan/config )" mark_service_started "net.${ifname}" ( - export SVCNAME="net.${ifname}" + export RC_SVCNAME="net.${ifname}" start ) || mark_service_stopped "net.${ifname}" done @@ -106,7 +106,7 @@ vlan_post_stop() for vlan in $(_get_vlans); do einfo "Removing VLAN ${vlan##*.} from ${IFACE}" ( - export SVCNAME="net.${vlan}" + export RC_SVCNAME="net.${vlan}" stop ) && { mark_service_stopped "net.${vlan}" diff --git a/net/wpa_supplicant.sh b/net/wpa_supplicant.sh index 204557ad..f7c4bc00 100644 --- a/net/wpa_supplicant.sh +++ b/net/wpa_supplicant.sh @@ -66,7 +66,7 @@ wpa_supplicant_pre_start() # the background unless we're not currently running if yesno ${IN_BACKGROUND}; then if ${wireless} && \ - service_started_daemon "${SVCNAME}" "${wpas}"; then + service_started_daemon "${RC_SVCNAME}" "${wpas}"; then SSID=$(_get_ssid "${IFACE}") SSIDVAR=$(shell_var "${SSID}") service_set_value "SSID" "${SSID}" @@ -177,7 +177,7 @@ wpa_supplicant_post_stop() if yesno "${IN_BACKGROUND}"; then # Only stop wpa_supplicant if it's not the controlling daemon - ! service_started_daemon "${SVCNAME}" "${wpas}" 1 + ! service_started_daemon "${RC_SVCNAME}" "${wpas}" 1 fi [ $? != 0 ] && return 0 diff --git a/sh/gendepends.sh.in b/sh/gendepends.sh.in index c80508d9..8ab50ad2 100644 --- a/sh/gendepends.sh.in +++ b/sh/gendepends.sh.in @@ -7,25 +7,25 @@ . @PREFIX@/@SYSCONFDIR@/init.d/functions.sh config() { - [ -n "$*" ] && echo "${SVCNAME} config $*" >&3 + [ -n "$*" ] && echo "${RC_SVCNAME} config $*" >&3 } need() { - [ -n "$*" ] && echo "${SVCNAME} ineed $*" >&3 + [ -n "$*" ] && echo "${RC_SVCNAME} ineed $*" >&3 } use() { - [ -n "$*" ] && echo "${SVCNAME} iuse $*" >&3 + [ -n "$*" ] && echo "${RC_SVCNAME} iuse $*" >&3 } before() { - [ -n "$*" ] && echo "${SVCNAME} ibefore $*" >&3 + [ -n "$*" ] && echo "${RC_SVCNAME} ibefore $*" >&3 } after() { - [ -n "$*" ] && echo "${SVCNAME} iafter $*" >&3 + [ -n "$*" ] && echo "${RC_SVCNAME} iafter $*" >&3 } provide() { - [ -n "$*" ] && echo "${SVCNAME} iprovide $*" >&3 + [ -n "$*" ] && echo "${RC_SVCNAME} iprovide $*" >&3 } keyword() { - [ -n "$*" ] && echo "${SVCNAME} keyword $*" >&3 + [ -n "$*" ] && echo "${RC_SVCNAME} keyword $*" >&3 } depend() { : @@ -47,35 +47,39 @@ do _done_dirs="${_done_dirs} ${_dir}" cd "${_dir}" - for SVCNAME in *; do - [ -x "${SVCNAME}" ] || continue + for RC_SERVICE in *; do + [ -x "${RC_SERVICE}" ] || continue # Only generate dependencies for runscripts - read one two < "${SVCNAME}" + read one two < "${RC_SERVICE}" [ "${one}" = "#!@PREFIX@/sbin/runscript" ] || continue unset one two - export SVCNAME=${SVCNAME##*/} + export RC_SVCNAME=${RC_SERVICE##*/} + + # Compat + export SVCNAME=${RC_SVCNAME} + ( # Save stdout in fd3, then remap it to stderr exec 3>&1 1>&2 - _rc_c=${SVCNAME%%.*} - if [ -n "${_rc_c}" -a "${_rc_c}" != "${SVCNAME}" ]; then + _rc_c=${RC_SVCNAME%%.*} + if [ -n "${_rc_c}" -a "${_rc_c}" != "${RC_SVCNAME}" ]; then if [ -e "${_dir}/../conf.d/${_rc_c}" ]; then . "${_dir}/../conf.d/${_rc_c}" fi fi unset _rc_c - if [ -e "${_dir}/../conf.d/${SVCNAME}" ]; then - . "${_dir}/../conf.d/${SVCNAME}" + if [ -e "${_dir}/../conf.d/${RC_SVCNAME}" ]; then + . "${_dir}/../conf.d/${RC_SVCNAME}" fi [ -e @PREFIX@/@SYSCONFDIR@/rc.conf ] && . @PREFIX@/@SYSCONFDIR@/rc.conf - if . "${_dir}/${SVCNAME}"; then - echo "${SVCNAME}" >&3 + if . "${_dir}/${RC_SVCNAME}"; then + echo "${RC_SVCNAME}" >&3 depend # Add any user defined depends @@ -85,9 +89,9 @@ do IFS=: set -- ${_deptype} unset IFS - eval _depends=\$rc_$(shell_var "${SVCNAME}")_$1 + eval _depends=\$rc_$(shell_var "${RC_SVCNAME}")_$1 [ -z "${_depends}" ] && eval _depends=\$rc_$1 - [ -z "${_depends}" ] && eval _depends=\$RC_$(shell_var "${SVCNAME}")_$2 + [ -z "${_depends}" ] && eval _depends=\$RC_$(shell_var "${RC_SVCNAME}")_$2 [ -z "${_depends}" ] && eval _depends=\$RC_$2 $1 ${_depends} diff --git a/sh/net.sh.in b/sh/net.sh.in index 1ad99983..8b03affc 100644 --- a/sh/net.sh.in +++ b/sh/net.sh.in @@ -15,7 +15,7 @@ __IFS=" " depend() { - local IFACE=${SVCNAME#*.} + local IFACE=${RC_SVCNAME#*.} local IFVAR=$(shell_var "${IFACE}") need localmount @@ -335,7 +335,7 @@ _load_modules() # Now load and wrap our functions if ! . "${MODULESDIR}/${mod}.sh"; then - eend 1 "${SVCNAME}: error loading module \`${mod}'" + eend 1 "${RC_SVCNAME}: error loading module \`${mod}'" exit 1 fi @@ -447,7 +447,7 @@ _load_config() start() { - local IFACE=${SVCNAME#*.} oneworked=false module= + local IFACE=${RC_SVCNAME#*.} oneworked=false module= local IFVAR=$(shell_var "${IFACE}") cmd= our_metric= local metric=0 @@ -487,7 +487,7 @@ start() if ! _wait_for_carrier; then if service_started devd; then ewarn "no carrier, but devd will start us when we have one" - mark_service_inactive "${SVCNAME}" + mark_service_inactive "${RC_SVCNAME}" else eerror "no carrier" fi @@ -617,7 +617,7 @@ ${routes}" stop() { - local IFACE=${SVCNAME#*.} module= + local IFACE=${RC_SVCNAME#*.} module= local IFVAR=$(shell_var "${IFACE}") opts= einfo "Bringing down interface ${IFACE}" diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in index 0df0aa0e..51777fae 100644 --- a/sh/runscript.sh.in +++ b/sh/runscript.sh.in @@ -14,20 +14,23 @@ if [ -r /sbin/livecd-functions.sh ]; then fi if [ -z "$1" -o -z "$2" ]; then - eerror "${SVCNAME}: not enough arguments" + eerror "${RC_SVCNAME}: not enough arguments" exit 1 fi # So daemons know where to recall us if needed export RC_SERVICE="$1" +# Compat +export SVCNAME=${RC_SVCNAME} + # Descript the init script to the user describe() { if [ -n "${description}" ]; then einfo "${description}" else - ewarn "No description for ${SVCNAME}" + ewarn "No description for ${RC_SVCNAME}" fi local svc= desc= @@ -45,8 +48,8 @@ yesno ${RC_DEBUG} && set -x _conf_d=${1%/*}/../conf.d # If we're net.eth0 or openvpn.work then load net or openvpn config -_c=${SVCNAME%%.*} -if [ -n "${_c}" -a "${_c}" != "${SVCNAME}" ]; then +_c=${RC_SVCNAME%%.*} +if [ -n "${_c}" -a "${_c}" != "${RC_SVCNAME}" ]; then if [ -e "${_conf_d}/${_c}.${RC_RUNLEVEL}" ]; then . "${_conf_d}/${_c}.${RC_RUNLEVEL}" elif [ -e "${_conf_d}/${_c}" ]; then @@ -56,10 +59,10 @@ fi unset _c # Overlay with our specific config -if [ -e "${_conf_d}/${SVCNAME}.${RC_RUNLEVEL}" ]; then - . "${_conf_d}/${SVCNAME}.${RC_RUNLEVEL}" -elif [ -e "${_conf_d}/${SVCNAME}" ]; then - . "${_conf_d}/${SVCNAME}" +if [ -e "${_conf_d}/${RC_SVCNAME}.${RC_RUNLEVEL}" ]; then + . "${_conf_d}/${RC_SVCNAME}.${RC_RUNLEVEL}" +elif [ -e "${_conf_d}/${RC_SVCNAME}" ]; then + . "${_conf_d}/${RC_SVCNAME}" fi unset _conf_d @@ -75,7 +78,7 @@ shift for _d in ${required_dirs}; do if [ ! -d ${_d} ]; then - eerror "${SVCNAME}: \`${_d}' is not a directory" + eerror "${RC_SVCNAME}: \`${_d}' is not a directory" exit 1 fi done @@ -83,7 +86,7 @@ unset _d for _f in ${required_files}; do if [ ! -r ${_f} ]; then - eerror "${SVCNAME}: \`${_f}' is not readable" + eerror "${RC_SVCNAME}: \`${_f}' is not readable" exit 1 fi done @@ -94,7 +97,7 @@ if [ -n "${command}" ]; then if ! type start >/dev/null 2>&1; then start() { local _background= - ebegin "Starting ${name:-${SVCNAME}}" + ebegin "Starting ${name:-${RC_SVCNAME}}" if yesno "${command_background}"; then _background="--background --pidfile" fi @@ -109,7 +112,7 @@ if [ -n "${command}" ]; then ${pidfile:+--pidfile} ${pidfile} \ ${_background} ${start_stop_daemon_args} \ -- ${command_args} - eend $? "Failed to start ${SVCNAME}" && return 0 + eend $? "Failed to start ${RC_SVCNAME}" && return 0 if yesno "${start_inactive}"; then if ! ${_inactive}; then mark_service_stopped @@ -125,12 +128,12 @@ fi if [ -n "${command}" -o -n "${procname}" -o -n "${pidfile}" ]; then if ! type stop >/dev/null 2>&1; then stop() { - ebegin "Stopping ${name:-${SVCNAME}}" + ebegin "Stopping ${name:-${RC_SVCNAME}}" start-stop-daemon --stop \ ${command:+--exec} ${command} \ ${procname:+--name} ${procname} \ ${pidfile:+--pidfile} ${pidfile} - eend $? "Failed to stop ${SVCNAME}" + eend $? "Failed to stop ${RC_SVCNAME}" } fi fi @@ -159,7 +162,7 @@ while [ -n "$1" ]; do for _cmd in ${extra_started_commands}; do if [ "${_cmd}" = "$1" ]; then if ! service_started; then - eerror "${SVCNAME}: cannot \`$1' as it has not been started" + eerror "${RC_SVCNAME}: cannot \`$1' as it has not been started" exit 1 fi fi @@ -179,12 +182,12 @@ while [ -n "$1" ]; do shift continue 2 else - eerror "${SVCNAME}: function \`$1' defined but does not exist" + eerror "${RC_SVCNAME}: function \`$1' defined but does not exist" exit 1 fi fi fi done - eerror "${SVCNAME}: unknown function \`$1'" + eerror "${RC_SVCNAME}: unknown function \`$1'" exit 1 done diff --git a/src/rc/rc-applets.c b/src/rc/rc-applets.c index 821832cd..42f839fa 100644 --- a/src/rc/rc-applets.c +++ b/src/rc/rc-applets.c @@ -207,7 +207,7 @@ static int do_service(int argc, char **argv) if (argc > 1) service = argv[1]; else - service = getenv("SVCNAME"); + service = getenv("RC_SVCNAME"); if (! service || *service == '\0') eerrorx("%s: no service specified", applet); @@ -229,7 +229,7 @@ static int do_service(int argc, char **argv) else if (strcmp(applet, "service_started_daemon") == 0) { d[0] = argv[1]; - service = getenv("SVCNAME"); + service = getenv("RC_SVCNAME"); if (argc > 3) { service = argv[1]; d[0] = argv[2]; @@ -252,7 +252,7 @@ static int do_service(int argc, char **argv) static int do_mark_service(int argc, char **argv) { bool ok = false; - char *svcname = getenv("SVCNAME"); + char *svcname = getenv("RC_SVCNAME"); char *service = NULL; char *runscript_pid; char *mtime; @@ -262,7 +262,7 @@ static int do_mark_service(int argc, char **argv) if (argc > 1) service = argv[1]; else - service = getenv("SVCNAME"); + service = getenv("RC_SVCNAME"); if (! service || *service == '\0') eerrorx("%s: no service specified", applet); @@ -311,7 +311,7 @@ static int do_mark_service(int argc, char **argv) static int do_value(int argc, char **argv) { bool ok = false; - char *service = getenv("SVCNAME"); + char *service = getenv("RC_SVCNAME"); char *option; if (! service) diff --git a/src/rc/runscript.c b/src/rc/runscript.c index a889e6a1..b0d6fca8 100644 --- a/src/rc/runscript.c +++ b/src/rc/runscript.c @@ -1129,7 +1129,7 @@ int runscript(int argc, char **argv) } setenv("EINFO_LOG", service, 1); - setenv("SVCNAME", applet, 1); + setenv("RC_SVCNAME", applet, 1); /* Set an env var so that we always know our pid regardless of any subshells the init script may create so that our mark_service_* diff --git a/src/rc/start-stop-daemon.c b/src/rc/start-stop-daemon.c index 6aec70b5..b9895826 100644 --- a/src/rc/start-stop-daemon.c +++ b/src/rc/start-stop-daemon.c @@ -583,7 +583,7 @@ int start_stop_daemon(int argc, char **argv) int stderr_fd; pid_t pid; int i; - char *svcname = getenv("SVCNAME"); + char *svcname = getenv("RC_SVCNAME"); RC_STRINGLIST *env_list; RC_STRING *env; char *path; @@ -974,8 +974,9 @@ int start_stop_daemon(int argc, char **argv) rc_stringlist_add(env_list, environ[i++]); TAILQ_FOREACH(env, env_list, entries) { if ((strncmp(env->value, "RC_", 3) == 0 && - strncmp(env->value, "RC_SERVICE=", strlen("RC_SERVICE=")) != 0) || - strncmp(env->value, "SSD_NICELEVEL=", strlen("SSD_NICELEVEL=")) == 0) + strncmp(env->value, "RC_SERVICE=", 10) != 0 && + strncmp(env->value, "RC_SVCNAME=", 10) != 0) || + strncmp(env->value, "SSD_NICELEVEL=", 14)) == 0) { p = strchr(env->value, '='); *p = '\0'; diff --git a/support/openvpn/down.sh b/support/openvpn/down.sh index 686838a8..b58abb98 100755 --- a/support/openvpn/down.sh +++ b/support/openvpn/down.sh @@ -3,7 +3,7 @@ # All rights reserved. Released under the 2-clause BSD license. # If we have a service specific script, run this now -[ -x "${SVCNAME}"-down.sh ] && "${SVCNAME}"-down.sh +[ -x "${RC_SVCNAME}"-down.sh ] && "${RC_SVCNAME}"-down.sh # Restore resolv.conf to how it was if type resolvconf >/dev/null 2>&1; then @@ -16,12 +16,10 @@ elif [ -e /etc/resolv.conf-"${dev}".sv ]; then fi # Re-enter the init script to stop any dependant services -service=/etc/init.d/"${SVCNAME}" -[ ! -x "${service}" ] && service=/usr/local/etc/init.d/"${SVCNAME}" -if [ -x "${service}" ]; then - if "${service}" --quiet status; then +if [ -x "${RC_SERVICE}" ]; then + if "${RC_SERVICE}" --quiet status; then export IN_BACKGROUND=YES - "${service}" --quiet stop + "${RC_SERVICE}" --quiet stop fi fi diff --git a/support/openvpn/up.sh b/support/openvpn/up.sh index 6d0c43e7..e466c263 100755 --- a/support/openvpn/up.sh +++ b/support/openvpn/up.sh @@ -18,8 +18,6 @@ # A possible workaround would be to just list multiple domain lines # and try and let resolvconf handle it -PATH=$PATH:/usr/local/sbin - NS= DOMAIN= SEARCH= @@ -59,19 +57,15 @@ if [ -n "${NS}" ]; then fi # Below section is OpenRC specific -# Quick summary - our init scripts are re-entrant and set the SVCNAME env var -# as we could have >1 openvpn service # If we have a service specific script, run this now -[ -x "${SVCNAME}"-up.sh ] && "${SVCNAME}"-up.sh +[ -x "${RC_SVCNAME}"-up.sh ] && "${RC_SVCNAME}"-up.sh # Re-enter the init script to start any dependant services -service=/etc/init.d/"${SVCNAME}" -[ ! -x "${service}" ] && service=/usr/local/etc/init.d/"${SVCNAME}" -if [ -x "${service}" ]; then - if ! "${service}" --quiet status; then +if [ -x "${RC_SERVICE}" ]; then + if ! "${RC_SERVICE}" --quiet status; then export IN_BACKGROUND=true - "${service}" --quiet start + "${RC_SERVICE}" --quiet start fi fi