diff options
author | Antoine Jacoutot <ajacoutot@cvs.openbsd.org> | 2014-10-11 13:42:50 +0000 |
---|---|---|
committer | Antoine Jacoutot <ajacoutot@cvs.openbsd.org> | 2014-10-11 13:42:50 +0000 |
commit | db848987bf87f4fe5f282d7b63c23bcaace548de (patch) | |
tree | aac081f79b82415d8175821814b3c12d0af8223e /usr.sbin | |
parent | 25b5e284ca3deb4636ba1aa9b8a3dbded1f40bf6 (diff) |
Add a new "default" command to display the default flags and whether a
service is enabled or disabled by default.
idea from Patrik Lundin
discussed with and ok schwarze@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/rcctl/rcctl.8 | 10 | ||||
-rw-r--r-- | usr.sbin/rcctl/rcctl.sh | 43 |
2 files changed, 40 insertions, 13 deletions
diff --git a/usr.sbin/rcctl/rcctl.8 b/usr.sbin/rcctl/rcctl.8 index cc403b0c29e..01fde733725 100644 --- a/usr.sbin/rcctl/rcctl.8 +++ b/usr.sbin/rcctl/rcctl.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: rcctl.8,v 1.8 2014/08/31 06:52:46 ajacoutot Exp $ +.\" $OpenBSD: rcctl.8,v 1.9 2014/10/11 13:42:49 ajacoutot Exp $ .\" .\" Copyright (c) 2014 Antoine Jacoutot <ajacoutot@openbsd.org> .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: August 31 2014 $ +.Dd $Mdocdate: October 11 2014 $ .Dt RCCTL 8 .Os .Sh NAME @@ -24,7 +24,7 @@ .Nm rcctl .Op Fl df .Sm off -.Cm enable | disable | status | Ar action +.Cm enable | disable | status | default | Ar action .Sm on .Op Ar service | daemon Op Cm flags Op Ar arguments .Sh DESCRIPTION @@ -75,6 +75,10 @@ Without an argument, display all services and .Ar daemon Ns _flags with their values in a format compatible with .Xr rc.conf 8 . +.It Cm default Op Ar service | daemon +Like +.Cm status +but return the default values instead of the configured ones. .It Oo Fl df Oc Ar action daemon Run the .Xr rc.d 8 diff --git a/usr.sbin/rcctl/rcctl.sh b/usr.sbin/rcctl/rcctl.sh index 007da851f37..5e17d31b596 100644 --- a/usr.sbin/rcctl/rcctl.sh +++ b/usr.sbin/rcctl/rcctl.sh @@ -1,6 +1,6 @@ #!/bin/sh # -# $OpenBSD: rcctl.sh,v 1.41 2014/10/10 15:59:36 ajacoutot Exp $ +# $OpenBSD: rcctl.sh,v 1.42 2014/10/11 13:42:49 ajacoutot Exp $ # # Copyright (c) 2014 Antoine Jacoutot <ajacoutot@openbsd.org> # Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org> @@ -27,7 +27,7 @@ _rc_parse_conf usage() { - _rc_err "usage: ${0##*/} [-df] enable|disable|status|action + _rc_err "usage: ${0##*/} [-df] enable|disable|status|default|action [service | daemon [flags [arguments]]]" } @@ -69,17 +69,37 @@ svc_default_enabled() return ${_ret} } -# for security reason and to prevent namespace pollution, only call in a -# subshell against base system daemons or disabled package scripts +# to prevent namespace pollution, only call in a subshell svc_default_enabled_flags() { local _svc=$1 [ -n "${_svc}" ] || return - FUNCS_ONLY=1 - rc_cmd() { } - . /etc/rc.d/${_svc} >/dev/null 2>&1 - [ -n "${daemon_flags}" ] && print -r -- ${daemon_flags} + 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_get_defaults() +{ + local _i _svc=$1 + + if [ -n "${_svc}" ]; then + print -r -- "$(svc_default_enabled_flags ${_svc})" + svc_default_enabled ${_svc} + else + for _i in $(ls -A /etc/rc.d | grep -v rc.subr); 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 } svc_get_flags() @@ -102,7 +122,7 @@ svc_get_flags() [ -z "${daemon_flags}" ] && \ daemon_flags="$(svc_default_enabled_flags ${_svc})" - print -r -- ${daemon_flags} | sed '/^$/d' + print -r -- "${daemon_flags}" | sed '/^$/d' fi } @@ -267,7 +287,7 @@ if [ -n "$svc" ]; then if ! svc_is_avail $svc; then _rc_err "${0##*/}: service $svc does not exist" 2 fi -elif [ "$action" != "status" ]; then +elif [ "$action" != "default" -a "$action" != "status" ] ; then usage fi @@ -288,6 +308,9 @@ if [ -n "$flag" ]; then fi case $action in + default) + svc_get_defaults $svc + ;; disable) needs_root $action if ! svc_is_base $svc && ! svc_is_special $svc; then |