/[baselayout]/trunk/net-scripts/net.modules.d/udhcpc
Gentoo

Contents of /trunk/net-scripts/net.modules.d/udhcpc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1753 - (show annotations) (download)
Fri Dec 9 15:08:06 2005 UTC (8 years, 4 months ago) by uberlord
File size: 3080 byte(s)
Remove nasty undocumented backgrounding as we now support
ifplugd, netplug and wpa_supplicant-0.4.x which do much better jobs.
1 #!/bin/bash
2 # Copyright (c) 2004-2005 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4
5 # Contributed by Roy Marples (uberlord@gentoo.org)
6
7 # Fix any potential localisation problems
8 # Note that LC_ALL trumps LC_anything_else according to locale(7)
9 udhcpc() {
10 LC_ALL=C /sbin/udhcpc "$@"
11 }
12
13 # void udhcpc_depend(void)
14 #
15 # Sets up the dependancies for the module
16 udhcpc_depend() {
17 after interface
18 provide dhcp
19 functions interface_exists interface_get_address
20 variables udhcpc dhcp
21 }
22
23 # bool udhcpc_check_installed(void)
24 #
25 # Returns 1 if udhcpc is installed, otherwise 0
26 udhcpc_check_installed() {
27 [[ -x /sbin/udhcpc ]] && return 0
28 ${1:-false} && eerror "For DHCP (udhcpc) support, emerge net-misc/udhcp"
29 return 1
30 }
31
32 # bool udhcpc_stop(char *iface)
33 #
34 # Stops udhcpc running on an interface
35 # Return 1 if we fail to stop udhcpc (if it's running) otherwise 0
36 udhcpc_stop() {
37 local iface="$1" pidfile="/var/run/udhcpc-$1.pid" d
38
39 [[ ! -f ${pidfile} ]] && return 0
40
41 ebegin "Stopping udhcpc on ${iface}"
42 local pid=$( < "${pidfile}" ) e=true
43
44 local ifvar=$( bash_variable "${iface}" )
45 d="dhcp_${ifvar}"
46 d=" ${!d} "
47 [[ ${d} == " " ]] && d=" ${dhcp} "
48
49 if [[ ${d} == *" release "* ]]; then
50 kill -s USR2 "${pid}" &>/dev/null
51 [[ -f "/var/cache/dhcp-${iface}.lease" ]] \
52 && rm "/var/cache/dhcp-${iface}.lease"
53 fi
54
55 kill -s TERM "${pid}" &>/dev/null
56
57 [[ -f ${pidfile} ]] && rm -f "${pidfile}"
58
59 ${e}
60 eend "$?"
61 return "$?"
62 }
63
64 # bool udhcpc_start(char *iface)
65 #
66 # Start DHCP on an interface by calling udhcpc $iface $options
67 #
68 # Returns 0 (true) when a DHCP address is obtained, otherwise 1
69 udhcpc_start() {
70 local iface="$1" opts pidfile="/var/run/udhcpc-$1.pid"
71 local cachefile="/var/cache/dhcp-$1.lease" d
72
73 interface_exists "${iface}" true || return 1
74
75 local ifvar=$( bash_variable "${iface}" ) opts
76 opts="udhcpc_${ifvar}"
77 opts="${!opts}"
78
79 d="dhcp_${ifvar}"
80 d=" ${!d} "
81 [[ ${d} == " " ]] && d=" ${dhcp} "
82
83 if [[ " ${d} " != *" nosendhost "* ]]; then
84 if [[ ! " ${opts}" =~ " -([hH] |-hostname=)" ]]; then
85 local hname=$( hostname )
86 [[ -n ${hname} && ${hname} != "(none)" && ${hname} != "localhost" ]] \
87 && opts="${opts} --hostname=${hname}"
88 fi
89 fi
90
91 # Bring up DHCP for this interface (or alias)
92 ebegin "Running udhcpc"
93
94 # Stop any instance of udhcpc on this interface
95 udhcpc_stop "${interface}"
96
97 # Try and load the cache if it exists
98 if [[ -f ${cachefile} ]]; then
99 if [[ " ${opts}" != *" --request="* && " ${opts} " != *" -r "* ]]; then
100 local x=$( < "${cachefile}" )
101 # Check for a valid ip
102 [[ ${x} == *.*.*.* ]] && opts="${opts} --request=${x}"
103 fi
104 fi
105
106 x=$( eval udhcpc "${opts}" --now --pidfile="${pidfile}" \
107 --interface="${iface}" \
108 --script="${MODULES_DIR}/helpers.d/udhcpc-wrapper" 2>&1 \
109 | egrep -v '^info,' )
110 # We just check the last 5 letters
111 [[ ${x:((${#x} - 5)):5} == "bound" ]]
112 eend "$?" "${x}" || return 1
113
114 # DHCP succeeded, show address retrieved
115 local addr=$( interface_get_address "${iface}" )
116 einfo "${iface} received address ${addr}"
117
118 return 0
119 }
120
121 # vim:ts=4

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.20