SVCNAME -> RC_SVCNAME, but export SVCNAME still for compat.

This commit is contained in:
Roy Marples 2008-03-19 19:57:24 +00:00
parent 6d2e1f7add
commit 6159a32f39
15 changed files with 80 additions and 80 deletions

View File

@ -2,7 +2,7 @@
# Copyright 2007-2008 Roy Marples <roy@marples.name>
# 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

View File

@ -18,7 +18,7 @@ depend()
reload()
{
ebegin "Reloading ${SVCNAME}"
ebegin "Reloading ${RC_SVCNAME}"
start-stop-daemon --signal SIGHUP --pidfile "${pidfile}"
eend $?
}

View File

@ -2,12 +2,12 @@
# Copyright 2007-2008 Roy Marples <roy@marples.name>
# 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}"

View File

@ -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.

View File

@ -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()

View File

@ -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}"

View File

@ -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

View File

@ -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}

View File

@ -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}"

View File

@ -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

View File

@ -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)

View File

@ -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_*

View File

@ -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';

View File

@ -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

View File

@ -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