/[baselayout]/branches/bsd-porting/net-scripts/net.modules.d/netplug
Gentoo

Contents of /branches/bsd-porting/net-scripts/net.modules.d/netplug

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1506 - (show annotations) (download)
Thu Sep 8 21:03:35 2005 UTC (9 years, 2 months ago) by uberlord
File size: 3284 byte(s)
netplug and ifplugd no longer error when interface does not exist
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 # char* netplug_provides(void)
8 #
9 # Returns a string to change module definition for starting up
10 netplug_provides() {
11 echo "plug"
12 }
13
14 # void netplug_depend(void)
15 #
16 # Sets up the dependancies for the module
17 netplug_depend() {
18 after macnet
19 before interface
20 }
21
22 # bool netplug_check_installed(void)
23 #
24 # Returns 0 if netplug is installed, otherwise 1
25 netplug_check_installed() {
26 if [[ ! -x /sbin/netplugd ]]; then
27 ${1:-false} && eerror "For netplug support, emerge sys-apps/netplug"
28 return 1
29 fi
30 return 0
31 }
32
33 # bool netplug_check_depends(void)
34 #
35 # Checks to see if we have the needed functions
36 netplug_check_depends() {
37 local f
38
39 for f in interface_exists interface_get_mac_address ; do
40 [[ $( type -t "${f}" ) == "function" ]] && continue
41 eerror "netplug: missing required function ${f}\n"
42 return 1
43 done
44
45 return 0
46 }
47
48 # bool netplug_pre_start(char *interface)
49 #
50 # Start netplug on an interface
51 netplug_pre_start() {
52 local iface="$1" timeout i
53 local pidfile="/var/run/netplug.${iface}.pid"
54
55 # We don't start netplug if we're being called from the background
56 ${IN_BACKGROUND} && return 0
57
58 interface_exists "${iface}" || return 0
59
60 # We need a valid MAC address
61 # It's a basic test to ensure it's not a virtual interface
62 local mac=$(interface_get_mac_address "${iface}")
63 if [[ -z ${mac} ]]; then
64 vewarn "netplug only works on interfaces with a valid MAC address"
65 return 0
66 fi
67
68 # We don't work on wirelesss interfaces
69 if [[ $(type -t wireless_check_extensions) == "function" ]]; then
70 if wireless_check_extensions "${iface}"; then
71 veinfo "netplug does not work on wireless interfaces"
72 return 0
73 fi
74 fi
75
76 ebegin "Starting netplug on ${iface}"
77
78 # We need the interface up for netplug to listen to netlink events
79 interface_up "${iface}"
80
81 # Mark the us as inactive so netplug can restart us
82 mark_service_inactive "net.${iface}"
83
84 # Start netplug
85 start-stop-daemon --start --exec /sbin/netplugd \
86 --pidfile "${pidfile}" \
87 -- -i "${iface}" -P -p "${pidfile}" -c /dev/null
88 eend "$?" || return 1
89
90 eindent
91
92 eval timeout=\"\$\{plug_timeout_${ifvar}\:-10}\"
93 if [[ ${timeout} == "0" ]]; then
94 ewarn "WARNING: infinite timeout set for ${iface} to come up"
95 elif [[ ${timeout} -lt 0 ]]; then
96 ewarn "WARNING: negative timeout set for ${iface}"
97 exit 0
98 fi
99
100 veinfo "Waiting for ${iface} to be marked as started"
101
102 i=0
103 while true ; do
104 if service_started "net.${iface}"; then
105 local addr=$( interface_get_address "${iface}" )
106 einfo "${iface} configured with address ${addr}"
107 exit 0
108 fi
109 sleep 1
110 (( i++ ))
111 [[ ${i} == "${timeout}" || ${i} -gt "${timeout}" ]] && break
112 done
113
114 eend 1 "Failed to configure ${iface} in the background"
115 exit 0
116 }
117
118 # bool netplug_post_stop(char *iface)
119 #
120 # Stops netplug on an interface
121 # Returns 0 (true) when successful, non-zero otherwise
122 netplug_post_stop() {
123 ${IN_BACKGROUND} && return 0
124 local iface="$1"
125 local pidfile="/var/run/netplug.${iface}.pid"
126
127 [[ ! -e ${pidfile} ]] && return 0
128
129 ebegin "Stopping netplug on ${iface}"
130 start-stop-daemon --stop --exec /sbin/netplugd \
131 --pidfile "${pidfile}"
132 eend $?
133 }
134
135 # vim:ts=4

  ViewVC Help
Powered by ViewVC 1.1.20