Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/etc Allow the run_rc_command function in rc.subr to pass ext...



details:   https://anonhg.NetBSD.org/src/rev/3b8a847e8575
branches:  trunk
changeset: 753099:3b8a847e8575
user:      jmmv <jmmv%NetBSD.org@localhost>
date:      Mon Mar 15 18:59:47 2010 +0000

description:
Allow the run_rc_command function in rc.subr to pass extra parameters to
the command being executed.  This is to allow rc.d scripts to do:

    run_rc_command "${@}"

instead of:

    run_rc_command "${1}"

and let the command handler (start, stop, etc.) receive the arguments after
the command name.

None of the default commands allow extra arguments, and they will error out
if any are given.  This is mostly useful for script-specific commands that
are only supposed to be used through the command line and, therefore, need
to provide a friendly interface.

Proposed in tech-userlevel@.  No major objections except for some minor
concerns regarding whether this should be allowed or not at all.  Note that
I'm not touching any of the rc.d scripts in the base system, so this is
effectively a no-op from the user point of view.

diffstat:

 etc/rc.subr |  13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

diffs (50 lines):

diff -r 12c41566b2cc -r 3b8a847e8575 etc/rc.subr
--- a/etc/rc.subr       Mon Mar 15 16:13:13 2010 +0000
+++ b/etc/rc.subr       Mon Mar 15 18:59:47 2010 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: rc.subr,v 1.80 2009/09/14 22:30:30 apb Exp $
+# $NetBSD: rc.subr,v 1.81 2010/03/15 18:59:47 jmmv Exp $
 #
 # Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -311,11 +311,11 @@
 }
 
 #
-# run_rc_command argument
+# run_rc_command argument [parameters]
 #      Search for argument in the list of supported commands, which is:
 #              "start stop restart rcvar status poll ${extra_commands}"
 #      If there's a match, run ${argument}_cmd or the default method
-#      (see below).
+#      (see below), and pass the optional list of parameters to it.
 #
 #      If argument has a given prefix, then change the operation as follows:
 #              Prefix  Operation
@@ -503,6 +503,7 @@
        if [ -z "$rc_arg" ]; then
                rc_usage "$_keywords"
        fi
+       shift   # remove $rc_arg from the positional parameters
 
        if [ -n "$flags" ]; then        # allow override from environment
                rc_flags=$flags
@@ -565,13 +566,17 @@
                                return 1
                        fi
 
-                       if ! eval $_cmd && [ -z "$rc_force" ]; then
+                       if ! eval $_cmd \"\${@}\" && [ -z "$rc_force" ]; then
                                return 1
                        fi
                        eval $_postcmd
                        return 0
                fi
 
+               if [ ${#} -gt 0 ]; then
+                       err 1 "the $rc_arg command does not take any parameters"
+               fi
+
                case "$rc_arg" in       # default operations...
 
                status)



Home | Main Index | Thread Index | Old Index