]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - etc/rc.d/dhclient
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / etc / rc.d / dhclient
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
12 ifn="$2"
13
14 name="dhclient"
15 rcvar=
16 pidfile="/var/run/${name}.${ifn}.pid"
17 start_precmd="dhclient_prestart"
18 stop_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.
22 dhclient_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
36 dhclient_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
54 load_rc_config $name
55 load_rc_config network
56
57 if [ -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
62 fi
63
64 run_rc_command "$1"