xref: /freebsd/libexec/rc/rc.d/dhclient (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1#!/bin/sh
2#
3#
4
5# PROVIDE: dhclient
6# KEYWORD: nojailvnet nostart
7
8. /etc/rc.subr
9. /etc/network.subr
10
11ifn="$2"
12
13name="dhclient"
14desc="Dynamic Host Configuration Protocol (DHCP) client"
15rcvar=
16pidfile="/var/run/dhclient/${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
52	# /var/run/dhclient is not guaranteed to exist,
53	# e.g. if /var/run is a tmpfs
54	install -d -o root -g wheel -m 755 ${pidfile%/*}
55
56	rc_flags="${rc_flags} ${ifn}"
57}
58
59load_rc_config $name
60load_rc_config network
61
62if [ -z $ifn ] ; then
63	# only complain if a command was specified but no interface
64	if [ -n "$1" ] ; then
65		err 1 "$0: no interface specified"
66	fi
67fi
68
69run_rc_command "$1"
70