/[vps]/baselayout-vserver/trunk/net-scripts/net.modules.d/ifplugd
Gentoo

Contents of /baselayout-vserver/trunk/net-scripts/net.modules.d/ifplugd

Parent Directory Parent Directory | Revision Log Revision Log


Revision 252 - (show annotations) (download)
Thu Feb 23 13:39:22 2006 UTC (12 years, 9 months ago) by phreak
File size: 3576 byte(s)
Merging baselayout r1924
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 # void ifplugd_depend(void)
8 #
9 # Sets up the dependancies for the module
10 ifplugd_depend() {
11 after macnet rename
12 before interface
13 functions interface_exists interface_get_mac_address
14 provide plug
15 }
16
17 # bool ifplugd_check_installed(void)
18 #
19 # Returns 0 if ifplugd is installed, otherwise 1
20 ifplugd_check_installed() {
21 if [[ ! -x /usr/sbin/ifplugd ]]; then
22 ${1:-false} && eerror "For ifplugd support, emerge sys-apps/ifplugd"
23 return 1
24 fi
25 return 0
26 }
27
28 # bool ifplugd_pre_start(char *interface)
29 #
30 # Start ifplugd on an interface
31 ifplugd_pre_start() {
32 local iface="$1" ifvar=$( bash_variable "$1" ) timeout opts
33 local pidfile="/var/run/ifplugd.${iface}.pid"
34
35 # We don't start ifplugd if we're being called from the background
36 ${IN_BACKGROUND} && return 0
37
38 interface_exists "${iface}" || return 0
39
40 # ifplugd could have been started by the old init script
41 if [[ -e ${pidfile} ]]; then
42 vewarn "ifplugd is already running on ${iface}"
43 return 0
44 fi
45
46 # We need a valid MAC address
47 # It's a basic test to ensure it's not a virtual interface
48 local mac=$(interface_get_mac_address "${iface}")
49 if [[ -z ${mac} ]]; then
50 vewarn "ifplugd only works on interfaces with a valid MAC address"
51 return 0
52 fi
53
54 # We don't work on bonded, bridges, tun/tap, vlan or wireless
55 for f in bonding bridge tuntap vlan ; do
56 if is_function "${f}_exists" ; then
57 if ${f}_exists "${iface}" ; then
58 veinfo "ifplugd does not work with ${f}"
59 return 0
60 fi
61 fi
62 done
63
64 # Do some options
65 opts="ifplugd_${ifvar}"
66
67 # We don't work on wirelesss interfaces
68 # Although ifplugd can, we prefer wpa_supplicant, unless explicitly told
69 # so via our options
70 if [[ " ${!opts} " != *" -m wlan "* \
71 && " ${!opts} " != *" --api-mode=wlan "* ]]; then
72 if is_function wireless_exists ; then
73 if wireless_exists "${iface}"; then
74 veinfo "ifplugd does not work on wireless interfaces"
75 return 0
76 fi
77 fi
78 fi
79
80 ebegin "Starting ifplugd on ${iface}"
81
82 # We need the interface up for ifplugd to listen to netlink events
83 interface_up "${iface}"
84
85 # Mark the us as inactive so ifplugd can restart us
86 mark_service_inactive "net.${iface}"
87
88 # Start ifplugd
89 eval start-stop-daemon --start --exec /usr/sbin/ifplugd \
90 --pidfile "${pidfile}" \
91 -- "${!opts}" --iface="${iface}"
92 eend "$?" || return 1
93
94 eindent
95
96 timeout="timeout_${ifvar}"
97 timeout="${!timeout:--1}"
98 if [[ ${timeout} == "0" ]]; then
99 ewarn "WARNING: infinite timeout set for ${iface} to come up"
100 elif [[ ${timeout} -lt 0 ]]; then
101 einfo "Backgrounding ..."
102 exit 0
103 fi
104
105 veinfo "Waiting for ${iface} to be marked as started"
106
107 local i=0
108 while true ; do
109 if service_started "net.${iface}"; then
110 local addr=$( interface_get_address "${iface}" )
111 einfo "${iface} configured with address ${addr}"
112 exit 0
113 fi
114 sleep 1
115 [[ ${timeout} == "0" ]] && continue
116 (( i++ ))
117 [[ ${i} == "${timeout}" || ${i} -gt "${timeout}" ]] && break
118 done
119
120 eend 1 "Failed to configure ${iface} in the background"
121 exit 0
122 }
123
124 # bool ifplugd_stop(char *iface)
125 #
126 # Stops ifplugd on an interface
127 # Returns 0 (true) when successful, non-zero otherwise
128 ifplugd_stop() {
129 ${IN_BACKGROUND} && return 0
130 local iface="$1"
131 local pidfile="/var/run/ifplugd.${iface}.pid"
132
133 [[ ! -e ${pidfile} ]] && return 0
134
135 ebegin "Stopping ifplugd on ${iface}"
136 start-stop-daemon --stop --exec /usr/sbin/ifplugd \
137 --pidfile "${pidfile}" --signal 3
138 eend $?
139 }
140
141 # vim:ts=4

  ViewVC Help
Powered by ViewVC 1.1.20