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