Module Name: src
Committed By: jmmv
Date: Mon Mar 15 18:59:48 UTC 2010
Modified Files:
src/etc: rc.subr
Log Message:
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-userle...@. 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.
To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/etc/rc.subr
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/etc/rc.subr
diff -u src/etc/rc.subr:1.80 src/etc/rc.subr:1.81
--- src/etc/rc.subr:1.80 Mon Sep 14 22:30:30 2009
+++ src/etc/rc.subr Mon Mar 15 18:59:47 2010
@@ -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)