From: Sascha Wildner Date: Wed, 6 Aug 2014 19:33:13 +0000 (+0200) Subject: rc.subr: Add quietstart and pass through arguments to rc scripts. X-Git-Url: https://gitweb.dragonflybsd.org/~mneumann/dragonfly.git/commitdiff_plain/17ddce9712dc66fa5d567d45ba9f4d0f5219bba5 rc.subr: Add quietstart and pass through arguments to rc scripts. None of our scripts handle additional arguments yet but it will be needed for moused starting/stopping via devd(8) and for bluetooth too. Taken-from: FreeBSD --- diff --git a/etc/rc.subr b/etc/rc.subr index f8eb674918..416aa1084b 100644 --- a/etc/rc.subr +++ b/etc/rc.subr @@ -470,9 +470,10 @@ get_pidfile_from_conf() # If argument has a given prefix, then change the operation as follows: # Prefix Operation # ------ --------- -# fast Skip the pid check, and set rc_fast=yes +# fast Skip the pid check, and set rc_fast=yes, rc_quiet=yes # force Set ${rcvar} to YES, and set rc_force=yes # one Set ${rcvar} to YES +# quiet Don't output some diagnostics, and set rc_quiet=yes # # The following globals are used: # @@ -598,6 +599,8 @@ get_pidfile_from_conf() # # rc_force Not empty if "force" was provided (q.v.) # +# rc_quiet Not empty if "quiet" was provided +# # dummy_rc_command() { @@ -626,10 +629,17 @@ run_rc_command() err 3 'run_rc_command: $name is not set.' fi + # Don't repeat the first argument when passing additional command- + # line arguments to the command subroutines. + # + shift 1 + rc_extra_args="$*" + case "$rc_arg" in fast*) # "fast" prefix; don't check pid rc_arg=${rc_arg#fast} rc_fast=yes + rc_quiet=yes ;; force*) # "force" prefix; always start rc_arg=${rc_arg#force} @@ -643,6 +653,12 @@ run_rc_command() if [ -n "${rcvar}" ]; then eval ${rcvar}=YES fi + ;; + quiet*) # "quiet" prefix; omit some messages + _rc_prefix=quiet + rc_arg=${rc_arg#${_rc_prefix}} + rc_quiet=yes + ;; esac eval _override_command=\$${name}_program @@ -716,7 +732,7 @@ run_rc_command() # if [ -n "$_precmd" ]; then debug "run_rc_command: evaluating ${_precmd}()." - eval $_precmd + eval $_precmd $rc_extra_args _return=$? check_early_term $rc_arg $_return "$rc_force" || return $(($?-1)) @@ -724,14 +740,14 @@ run_rc_command() if [ -n "$_cmd" ]; then debug "run_rc_command: evaluating ${_cmd}()." - eval $_cmd + eval $_cmd $rc_extra_args _return=$? check_early_term $rc_arg $_return "$rc_force" || return $(($?-1)) fi if [ -n "$_postcmd" ]; then debug "run_rc_command: evaluating ${_postcmd}()." - eval $_postcmd + eval $_postcmd $rc_extra_args _return=$? check_early_term $rc_arg $_return "" || return $(($?-1)) fi @@ -753,7 +769,9 @@ run_rc_command() start) if [ -n "$rc_pid" ]; then - echo "${name} already running? (pid=$rc_pid)." + if [ -z "$rc_quiet" ]; then + echo "${name} already running? (pid=$rc_pid)." + fi exit 1 fi @@ -918,7 +936,7 @@ $command $rc_flags $command_args" restart) if [ -n "$_precmd" ]; then - eval $_precmd + eval $_precmd $rc_extra_args _return=$? check_early_term $rc_arg $_return "$rc_force" || return $(($?-1)) fi @@ -930,12 +948,12 @@ $command $rc_flags $command_args" fi _rc_restart_done=YES - ( $0 ${rc_force:+force}stop ) - $0 ${rc_force:+force}start + ( $0 ${rc_force:+force}stop $rc_extra_args ) + $0 ${rc_force:+force}start $rc_extra_args _return=$? if [ -n "$_postcmd" ]; then - eval $_postcmd + eval $_postcmd $rc_extra_args adjust_return_code $? _return=$? fi @@ -1089,7 +1107,7 @@ load_rc_config() # rc_usage() { - echo -n 1>&2 "Usage: $0 [fast|force|one](" + echo -n 1>&2 "Usage: $0 [fast|force|one|quiet](" _sep= for _elem in $*; do diff --git a/share/man/man8/rc.subr.8 b/share/man/man8/rc.subr.8 index 71723c0d4b..5d8b8091d4 100644 --- a/share/man/man8/rc.subr.8 +++ b/share/man/man8/rc.subr.8 @@ -1,6 +1,5 @@ .\" $NetBSD: rc.subr.8,v 1.9 2002/07/08 16:14:55 atatat Exp $ .\" $FreeBSD: src/share/man/man8/rc.subr.8,v 1.3 2003/04/22 05:13:55 dougb Exp $ -.\" $DragonFly: src/share/man/man8/rc.subr.8,v 1.6 2008/09/06 21:31:21 swildner Exp $ .\" Copyright (c) 2002 The NetBSD Foundation, Inc. .\" All rights reserved. .\" @@ -35,7 +34,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd September 6, 2008 +.Dd August 6, 2014 .Dt RC.SUBR 8 .Os .Sh NAME @@ -329,7 +328,9 @@ with .Ar commands being the list of valid arguments prefixed by -.Dq "[fast|force|one]" . +.Sm off +.Dq Bq Li fast | force | one | quiet . +.Sm on .It Ic reverse_list Ar item Op Ar ... Print the list of .Ar items @@ -382,6 +383,22 @@ tests failing . Skip the checks for .Sy rcvar being set to yes, but performs all the other prerequisite tests. +.It Li quiet +Inhibits some verbose diagnostics. +Currently, this includes messages +.Qq Starting ${name} +.\"(as checked by +.\".Ic check_startmsgs +.\"inside +.\".Nm ) +and errors about usage of services that are not enabled in +.Xr rc.conf 5 . +This prefix also sets +.Va rc_quiet Ns = Ns Li YES . +.Em Please, note: +.Va rc_quiet +is not intended to completely mask all debug and warning messages, +but only certain small classes of them. .El .Pp .Ic run_rc_command