Date: Mon, 26 Jul 2004 12:28:31 +0300 From: Mike Makonnen <mtm@identd.net> To: freebsd-rc@freebsd.org Subject: rc.d/netif cleanups Message-ID: <20040726092831.GC1260@rogue.acs-et.com>
next in thread | raw e-mail | index | archive | help
--E39vaYmALEf/7YXx Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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@identd.net | Fingerprint: AC7B 5672 2D11 F4D0 EBF8 5279 5359 2B82 7CD4 1F55 mtm@FreeBSD.Org| FreeBSD - Unleash the Daemon ! --E39vaYmALEf/7YXx Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=diff 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 $* --E39vaYmALEf/7YXx--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040726092831.GC1260>