From ad844b42a2ded6583ac9176413a9ef594c5e677b Mon Sep 17 00:00:00 2001 From: des Date: Thu, 13 Oct 2011 17:20:45 +0000 Subject: Make dhclient use a pid file. Modify the rc script accordingly; while there, clean it up and add some error checks. Glanced at by: brooks@ MFC after: 3 weeks --- etc/rc.d/dhclient | 48 ++++++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 32 deletions(-) (limited to 'etc') diff --git a/etc/rc.d/dhclient b/etc/rc.d/dhclient index c7e4b4d..8faf0ec 100755 --- a/etc/rc.d/dhclient +++ b/etc/rc.d/dhclient @@ -9,55 +9,39 @@ . /etc/rc.subr . /etc/network.subr +ifn="$2" + name="dhclient" rcvar= -start_cmd="dhclient_start" -stop_cmd="dhclient_stop" +pidfile="/var/run/${name}.${ifn}.pid" +start_precmd="dhclient_prestart" -dhclient_start() +dhclient_prestart() { - # prevent unnecessary restarts - # XXX: dhclient had better create a pidfile - if [ -x /bin/pgrep ]; then - pids=`/bin/pgrep -f "dhclient: $ifn(\$| .*)"` - if [ -n "$pids" ]; then - sleep 1 - pids=`/bin/pgrep -f "dhclient: $ifn(\$| .*)"` - if [ -n "$pids" ]; then - exit 0 - fi - elif [ -e /var/run/dhclient.pid ]; then - if [ -n "`pgrep -F /var/run/dhclient.pid`" ]; then - exit 0 - fi - fi - fi - - # Override for $ifn specific flags (see rc.subr for $flags setting) - specific=`get_if_var $ifn dhclient_flags_IF` + # Interface-specific flags (see rc.subr for $flags setting) + specific=$(get_if_var $ifn dhclient_flags_IF) if [ -z "$flags" -a -n "$specific" ]; then rc_flags=$specific fi - background_dhclient=`get_if_var $ifn background_dhclient_IF $background_dhclient` + background_dhclient=$(get_if_var $ifn background_dhclient_IF $background_dhclient) if checkyesno background_dhclient; then rc_flags="${rc_flags} -b" fi - ${dhclient_program} ${rc_flags} $ifn -} - -dhclient_stop() -{ - ifconfig $ifn down # cause dhclient to die + rc_flags="${rc_flags} ${ifn}" } -ifn="$2" - load_rc_config $name load_rc_config network -if ! dhcpif $ifn; then +if [ -z $ifn ] ; then + # only complain if a command was specified but no interface + if [ -n "$1" ] ; then + echo 1>&2 "$0: no interface specified" + return 1 + fi +elif [ -n "${rc_force}" ] && ! dhcpif $ifn; then return 1 fi -- cgit v1.1