1#!/bin/sh 2# 3# $FreeBSD$ 4# 5 6# PROVIDE: dhclient 7# KEYWORD: nojailvnet nostart 8 9. /etc/rc.subr 10. /etc/network.subr 11 12ifn="$2" 13 14name="dhclient" 15desc="Dynamic Host Configuration Protocol (DHCP) client" 16rcvar= 17pidfile="/var/run/dhclient/${name}.${ifn}.pid" 18start_precmd="dhclient_prestart" 19stop_precmd="dhclient_pre_check" 20 21# rc_force check can only be done at the run_rc_command 22# time, so we're testing it in the pre* hooks. 23dhclient_pre_check() 24{ 25 if [ -z "${rc_force}" ] && ! dhcpif $ifn; then 26 local msg 27 msg="'$ifn' is not a DHCP-enabled interface" 28 if [ -z "${rc_quiet}" ]; then 29 echo "$msg" 30 else 31 debug "$msg" 32 fi 33 exit 1 34 fi 35} 36 37dhclient_prestart() 38{ 39 dhclient_pre_check 40 41 # Interface-specific flags (see rc.subr for $flags setting) 42 specific=$(get_if_var $ifn dhclient_flags_IF) 43 if [ -z "$flags" -a -n "$specific" ]; then 44 rc_flags=$specific 45 fi 46 47 background_dhclient=$(get_if_var $ifn background_dhclient_IF $background_dhclient) 48 if checkyesno background_dhclient; then 49 rc_flags="${rc_flags} -b" 50 fi 51 52 53 # /var/run/dhclient is not guaranteed to exist, 54 # e.g. if /var/run is a tmpfs 55 install -d -o root -g wheel -m 755 ${pidfile%/*} 56 57 rc_flags="${rc_flags} ${ifn}" 58} 59 60load_rc_config $name 61load_rc_config network 62 63if [ -z $ifn ] ; then 64 # only complain if a command was specified but no interface 65 if [ -n "$1" ] ; then 66 err 1 "$0: no interface specified" 67 fi 68fi 69 70run_rc_command "$1" 71