summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntoine Jacoutot <ajacoutot@cvs.openbsd.org>2014-12-30 15:33:54 +0000
committerAntoine Jacoutot <ajacoutot@cvs.openbsd.org>2014-12-30 15:33:54 +0000
commite104fae1b63988941f375c10fc35f41fcddd5102 (patch)
tree6a7a595eb46be47e3de93f5bb436a3287ca7392e
parentc209eb74e9646102c4bc8a5675bcad32431dace6 (diff)
Rename a few functions name. Will help factorize some stuffs.
-rw-r--r--usr.sbin/rcctl/rcctl.sh176
1 files changed, 88 insertions, 88 deletions
diff --git a/usr.sbin/rcctl/rcctl.sh b/usr.sbin/rcctl/rcctl.sh
index 1f094d07022..1dfd2563299 100644
--- a/usr.sbin/rcctl/rcctl.sh
+++ b/usr.sbin/rcctl/rcctl.sh
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# $OpenBSD: rcctl.sh,v 1.53 2014/12/30 15:31:33 robert Exp $
+# $OpenBSD: rcctl.sh,v 1.54 2014/12/30 15:33:53 ajacoutot Exp $
#
# Copyright (c) 2014 Antoine Jacoutot <ajacoutot@openbsd.org>
# Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -66,63 +66,56 @@ rcconf_edit_end()
fi
}
-svc_default_enabled()
+svc_avail()
{
local _svc=$1
- [ -n "${_svc}" ] || return
- local _ret=1
+ [ -n "${_svc}" ] || return 1
- _rc_parse_conf /etc/rc.conf
- svc_is_enabled ${_svc} && _ret=0
- _rc_parse_conf
+ [ "${_svc}" = "rc.subr" ] && return 1
+ [ -x "/etc/rc.d/${_svc}" ] && return 0
+ svc_special ${_svc}
+}
- return ${_ret}
+svc_base()
+{
+ local _svc=$1
+ [ -n "${_svc}" ] || return
+
+ grep "^start_daemon " /etc/rc | cut -d ' ' -f2- | grep -qw -- ${_svc}
}
-# to prevent namespace pollution, only call in a subshell
-svc_default_enabled_flags()
+svc_enabled()
{
local _svc=$1
[ -n "${_svc}" ] || return
- if svc_is_special ${_svc}; then
- svc_default_enabled ${_svc} && echo "YES" || echo "NO"
- else
- FUNCS_ONLY=1
- rc_cmd() { }
- . /etc/rc.d/${_svc} >/dev/null 2>&1
- [ -n "${daemon_flags}" ] && print -r -- "${daemon_flags}"
- fi
+ [ "$(svc_flags ${_svc})" != "NO" ]
}
-svc_get_defaults()
+svc_enabled_default()
{
- local _i _svc=$1
+ local _svc=$1
+ [ -n "${_svc}" ] || return
+ local _ret=1
- if [ -n "${_svc}" ]; then
- ( svc_default_enabled_flags ${_svc} )
- svc_default_enabled ${_svc}
- else
- for _i in $(ls_rcscripts); do
- echo "${_i}_flags=$(svc_default_enabled_flags ${_i})"
- done
- for _i in ${_special_services}; do
- echo "${_i}=$(svc_default_enabled_flags ${_i})"
- done
- fi
+ _rc_parse_conf /etc/rc.conf
+ svc_enabled ${_svc} && _ret=0
+ _rc_parse_conf
+
+ return ${_ret}
}
-svc_get_flags()
+svc_flags()
{
local _svc=$1
[ -n "${_svc}" ] || return
local daemon_flags
- if svc_is_special ${_svc}; then
+ if svc_special ${_svc}; then
echo "$(eval echo \${${_svc}})"
else
# set pkg daemon_flags to "NO" to match base svc
- if ! svc_is_base ${_svc}; then
+ if ! svc_base ${_svc}; then
if ! echo ${pkg_scripts} | grep -qw -- ${_svc}; then
echo "NO" && return
fi
@@ -130,64 +123,71 @@ svc_get_flags()
[ -z "${daemon_flags}" ] && \
daemon_flags="$(eval echo \"\${${_svc}_flags}\")"
[ -z "${daemon_flags}" ] && \
- daemon_flags="$(svc_default_enabled_flags ${_svc})"
+ daemon_flags="$(svc_flags_default ${_svc})"
[ -n "${daemon_flags}" ] && print -r -- "${daemon_flags}"
fi
}
-svc_get_status()
+# to prevent namespace pollution, only call in a subshell
+svc_flags_default()
{
- local _i _svc=$1
+ local _svc=$1
+ [ -n "${_svc}" ] || return
- if [ -n "${_svc}" ]; then
- svc_get_flags ${_svc}
- svc_is_enabled ${_svc}
+ if svc_special ${_svc}; then
+ svc_enabled_default ${_svc} && echo "YES" || echo "NO"
else
- for _i in $(ls_rcscripts); do
- echo "${_i}_flags=$(svc_get_flags ${_i})"
- done
- for _i in ${_special_services}; do
- echo "${_i}=$(svc_get_flags ${_i})"
- done
+ FUNCS_ONLY=1
+ rc_cmd() { }
+ . /etc/rc.d/${_svc} >/dev/null 2>&1
+ [ -n "${daemon_flags}" ] && print -r -- "${daemon_flags}"
fi
}
-svc_is_avail()
-{
- local _svc=$1
- [ -n "${_svc}" ] || return 1
-
- [ "${_svc}" = "rc.subr" ] && return 1
- [ -x "/etc/rc.d/${_svc}" ] && return 0
- svc_is_special ${_svc}
-}
-
-svc_is_base()
+svc_special()
{
local _svc=$1
[ -n "${_svc}" ] || return
- grep "^start_daemon " /etc/rc | cut -d ' ' -f2- | grep -qw -- ${_svc}
+ echo ${_special_services} | grep -qw -- ${_svc}
}
-svc_is_enabled()
+svc_status()
{
- local _svc=$1
- [ -n "${_svc}" ] || return
+ local _i _svc=$1
- [ "$(svc_get_flags ${_svc})" != "NO" ]
+ if [ -n "${_svc}" ]; then
+ svc_flags ${_svc}
+ svc_enabled ${_svc}
+ else
+ for _i in $(ls_rcscripts); do
+ echo "${_i}_flags=$(svc_flags ${_i})"
+ done
+ for _i in ${_special_services}; do
+ echo "${_i}=$(svc_flags ${_i})"
+ done
+ fi
}
-svc_is_special()
+svc_status_default()
{
- local _svc=$1
- [ -n "${_svc}" ] || return
+ local _i _svc=$1
- echo ${_special_services} | grep -qw -- ${_svc}
+ if [ -n "${_svc}" ]; then
+ ( svc_flags_default ${_svc} )
+ svc_enabled_default ${_svc}
+ else
+ for _i in $(ls_rcscripts); do
+ echo "${_i}_flags=$(svc_flags_default ${_i})"
+ done
+ for _i in ${_special_services}; do
+ echo "${_i}=$(svc_flags_default ${_i})"
+ done
+ fi
}
-append_to_pkg_scripts()
+pkg_scripts_append()
{
local _svc=$1
[ -n "${_svc}" ] || return
@@ -202,7 +202,7 @@ append_to_pkg_scripts()
rcconf_edit_end
}
-order_pkg_scripts()
+pkg_scripts_order()
{
local _svcs="$*"
[ -n "${_svcs}" ] || return
@@ -210,9 +210,9 @@ order_pkg_scripts()
needs_root ${action}
local _pkg_scripts _svc
for _svc in ${_svcs}; do
- if svc_is_base ${_svc} || svc_is_special ${_svc}; then
+ if svc_base ${_svc} || svc_special ${_svc}; then
_rc_err "${0##*/}: ${_svc} is not a pkg script"
- elif ! svc_is_enabled ${_svc}; then
+ elif ! svc_enabled ${_svc}; then
_rc_err "${0##*/}: ${_svc} is not enabled"
fi
done
@@ -224,7 +224,7 @@ order_pkg_scripts()
rcconf_edit_end
}
-rm_from_pkg_scripts()
+pkg_scripts_rm()
{
local _svc=$1
[ -n "${_svc}" ] || return
@@ -243,10 +243,10 @@ add_flags()
local _svc=$1
[ -n "${_svc}" ] || return
- if svc_is_special ${_svc}; then
+ if svc_special ${_svc}; then
rcconf_edit_begin
grep -v "^${_svc}.*=" /etc/rc.conf.local >${_TMP_RCCONF}
- if ! svc_default_enabled ${_svc}; then
+ if ! svc_enabled_default ${_svc}; then
echo "${_svc}=YES" >>${_TMP_RCCONF}
fi
rcconf_edit_end
@@ -266,7 +266,7 @@ add_flags()
# unset flags if they match the default enabled ones
if [ -n "${_flags}" ]; then
- [ "${_flags}" = "$(svc_default_enabled_flags ${_svc})" ] && \
+ [ "${_flags}" = "$(svc_flags_default ${_svc})" ] && \
unset _flags
fi
@@ -276,7 +276,7 @@ add_flags()
rcconf_edit_begin
grep -v "^${_svc}_flags.*=" /etc/rc.conf.local >${_TMP_RCCONF}
if [ -n "${_flags}" ] || \
- ( svc_is_base ${_svc} && ! svc_default_enabled ${_svc} ); then
+ ( svc_base ${_svc} && ! svc_enabled_default ${_svc} ); then
echo "${_svc}_flags=${_flags}" >>${_TMP_RCCONF}
fi
rcconf_edit_end
@@ -288,14 +288,14 @@ rm_flags()
[ -n "${_svc}" ] || return
rcconf_edit_begin
- if svc_is_special ${_svc}; then
+ if svc_special ${_svc}; then
grep -v "^${_svc}.*=" /etc/rc.conf.local >${_TMP_RCCONF}
- if svc_default_enabled ${_svc}; then
+ if svc_enabled_default ${_svc}; then
echo "${_svc}=NO" >>${_TMP_RCCONF}
fi
else
grep -v "^${_svc}_flags.*=" /etc/rc.conf.local >${_TMP_RCCONF}
- if svc_default_enabled ${_svc}; then
+ if svc_enabled_default ${_svc}; then
echo "${_svc}_flags=NO" >>${_TMP_RCCONF}
fi
fi
@@ -325,7 +325,7 @@ else
fi
if [ -n "${svc}" ]; then
- if ! svc_is_avail ${svc}; then
+ if ! svc_avail ${svc}; then
_rc_err "${0##*/}: service ${svc} does not exist" 2
fi
elif [[ ${action} != @(default|order|status) ]] ; then
@@ -337,7 +337,7 @@ if [ -n "${flag}" ]; then
if [ "${action}" != "enable" ]; then
_rc_err "${0##*/}: \"${flag}\" can only be set with \"enable\""
fi
- if svc_is_special ${svc} && [ -n "${flags}" ]; then
+ if svc_special ${svc} && [ -n "${flags}" ]; then
_rc_err "${0##*/}: \"${svc}\" is a special variable, cannot set \"${flag}\""
fi
if [ "${flag}" = "flags" -a "${flags}" = "NO" ]; then
@@ -350,35 +350,35 @@ fi
case ${action} in
default)
- svc_get_defaults ${svc}
+ svc_status_default ${svc}
;;
disable)
needs_root ${action}
- if ! svc_is_base ${svc} && ! svc_is_special ${svc}; then
- rm_from_pkg_scripts ${svc}
+ if ! svc_base ${svc} && ! svc_special ${svc}; then
+ pkg_scripts_rm ${svc}
fi
rm_flags ${svc}
;;
enable)
needs_root ${action}
add_flags ${svc} "${flag}" "${flags}"
- if ! svc_is_base ${svc} && ! svc_is_special ${svc}; then
- append_to_pkg_scripts ${svc}
+ if ! svc_base ${svc} && ! svc_special ${svc}; then
+ pkg_scripts_append ${svc}
fi
;;
order)
if [ -n "${svcs}" ]; then
needs_root ${action}
- order_pkg_scripts ${svcs}
+ pkg_scripts_order ${svcs}
else
[[ -z ${pkg_scripts} ]] || echo ${pkg_scripts}
fi
;;
status)
- svc_get_status ${svc}
+ svc_status ${svc}
;;
start|stop|restart|reload|check)
- if svc_is_special ${svc}; then
+ if svc_special ${svc}; then
_rc_err "${0##*/}: \"${svc}\" is a special variable, no rc.d(8) script"
fi
/etc/rc.d/${svc} ${_RC_DEBUG} ${_RC_FORCE} ${action}