]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - etc/rc.d/dhclient
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.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 name="dhclient"
13 rcvar=
14 start_cmd="dhclient_start"
15 stop_cmd="dhclient_stop"
16
17 dhclient_start()
18 {
19         # prevent unnecessary restarts
20         # XXX: dhclient had better create a pidfile
21         if [ -x /bin/pgrep ]; then
22                 pids=`/bin/pgrep -f "dhclient: $ifn(\$| .*)"`
23                 if [ -n "$pids" ]; then
24                         sleep 1
25                         pids=`/bin/pgrep -f "dhclient: $ifn(\$| .*)"`
26                         if [ -n "$pids" ]; then
27                                 exit 0
28                         fi
29                 elif [ -e /var/run/dhclient.pid ]; then
30                         if [ -n "`pgrep -F /var/run/dhclient.pid`" ]; then
31                                 exit 0
32                         fi
33                 fi
34         fi
35
36         # Override for $ifn specific flags (see rc.subr for $flags setting)
37         specific=`get_if_var $ifn dhclient_flags_IF`
38         if [ -z "$flags" -a -n "$specific" ]; then
39                 rc_flags=$specific
40         fi
41
42         background_dhclient=`get_if_var $ifn background_dhclient_IF $background_dhclient`
43         if checkyesno background_dhclient; then
44                 rc_flags="${rc_flags} -b"
45         fi
46
47         ${dhclient_program} ${rc_flags} $ifn
48 }
49
50 dhclient_stop()
51 {
52         ifconfig $ifn down      # cause dhclient to die
53 }
54
55 ifn="$2"
56
57 load_rc_config $name
58 load_rc_config network
59
60 if ! dhcpif $ifn; then
61         return 1
62 fi
63
64 run_rc_command "$1"