rc.d/netif cleanups
Mike Makonnen
mtm at identd.net
Mon Jul 26 02:27:38 PDT 2004
hi folks,
Currently, rc.d/netif allows one to start or stop a specific interface.
However, you can't specify more than one interface and it doesn't work
with the 'restart' command. To fix this I've modified rc.subr to pass
additional commands supplied on the command line to the custom
start/prestart/poststart/stop/prestop/poststop... I would appreciate
comments and additional testing. Thanks.
Cheers.
--
Mike Makonnen | GPG-KEY: http://www.identd.net/~mtm/mtm.asc
mtm at identd.net | Fingerprint: AC7B 5672 2D11 F4D0 EBF8 5279 5359 2B82 7CD4 1F55
mtm at FreeBSD.Org| FreeBSD - Unleash the Daemon !
-------------- next part --------------
Index: etc/rc.subr
===================================================================
RCS file: /home/ncvs/src/etc/rc.subr,v
retrieving revision 1.30
diff -u -r1.30 rc.subr
--- etc/rc.subr 4 Jul 2004 07:21:18 -0000 1.30
+++ etc/rc.subr 25 Jul 2004 18:40:52 -0000
@@ -463,6 +463,12 @@
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="$*"
+
_rc_prefix=
case "$rc_arg" in
fast*) # "fast" prefix; don't check pid
@@ -556,7 +562,7 @@
#
if [ -n "$_precmd" ]; then
debug "run_rc_command: evaluating ${_precmd}()."
- eval $_precmd
+ eval $_precmd $rc_extra_args
_return=$?
[ $_return -ne 0 ] && [ -z "$rc_force" ] &&
return 1
@@ -564,7 +570,7 @@
if [ -n "$_cmd" ]; then
debug "run_rc_command: evaluating ${_cmd}()."
- eval $_cmd
+ eval $_cmd $rc_extra_args
_return=$?
[ $_return -ne 0 ] && [ -z "$rc_force" ] &&
return 1
@@ -572,7 +578,7 @@
if [ -n "$_postcmd" ]; then
debug "run_rc_command: evaluating ${_postcmd}()."
- eval $_postcmd
+ eval $_postcmd $rc_extra_args
_return=$?
fi
return $_return
@@ -751,7 +757,7 @@
restart)
if [ -n "$_precmd" ]; then
- eval $_precmd
+ eval $_precmd $rc_extra_args
_return=$?
[ $_return -ne 0 ] && [ -z "$rc_force" ] &&
return 1
@@ -764,11 +770,11 @@
fi
_rc_restart_done=true
- ( $0 ${_rc_prefix}stop )
- $0 ${_rc_prefix}start
+ ( $0 ${_rc_prefix}stop $rc_extra_args )
+ $0 ${_rc_prefix}start $rc_extra_args
if [ -n "$_postcmd" ]; then
- eval $_postcmd
+ eval $_postcmd $rc_extra_args
_return=$?
fi
;;
Index: etc/rc.d/netif
===================================================================
RCS file: /home/ncvs/src/etc/rc.d/netif,v
retrieving revision 1.9
diff -u -r1.9 netif
--- etc/rc.d/netif 20 May 2004 15:53:49 -0000 1.9
+++ etc/rc.d/netif 25 Jul 2004 19:11:02 -0000
@@ -42,6 +42,10 @@
network_start()
{
+ # Set the list of interfaces to work on.
+ #
+ _cmdifn=$*
+
if [ -z "$_cmdifn" ]; then
#
# We're operating as a general network start routine.
@@ -65,6 +69,10 @@
network_stop()
{
+ # Set the list of interfaces to work on.
+ #
+ _cmdifn=$*
+
echo -n "Stopping network:"
# Deconfigure the interface(s)
@@ -96,12 +104,17 @@
# Set the scope of the command (all interfaces or just one).
#
- _cooked_list="$_ifn_list"
+ _cooked_list=
if [ -n "$_cmdifn" ]; then
- eval _cooked_list=\"`expr "$_ifn_list" : ".*\($_cmdifn\).*"`\"
- if [ -z "$_cooked_list" ]; then
- err 1 "No such network interface: $_cmdifn"
- fi
+ for i in $_cmdifn ; do
+ eval _if=\"`expr "$_ifn_list" : ".*\(${i}\).*"`\"
+ if [ -z "$_if" ]; then
+ err 1 "No such network interface: $i"
+ fi
+ _cooked_list="$_cooked_list $_if"
+ done
+ else
+ _cooked_list="$_ifn_list"
fi
for ifn in ${_cooked_list}; do
@@ -159,9 +172,5 @@
return $cfg
}
-if [ -n "$2" ]; then
- _cmdifn="$2"
-fi
-
load_rc_config $name
-run_rc_command "$1"
+run_rc_command $*
More information about the freebsd-rc
mailing list