/[baselayout]/trunk/net.Linux/netplugd.sh
Gentoo

Contents of /trunk/net.Linux/netplugd.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2547 - (show annotations) (download) (as text)
Thu Apr 5 11:18:42 2007 UTC (7 years, 6 months ago) by uberlord
File MIME type: text/x-sh
File size: 2179 byte(s)
    Rewrite the core parts in C. We now provide librc so other programs can
    query runlevels, services and state without using bash. We also provide
    libeinfo so other programs can easily use our informational functions.

    As such, we have dropped the requirement of using bash as the init script
    shell. We now use /bin/sh and have strived to make the scripts as portable
    as possible. Shells that work are bash and dash. busybox works provided
    you disable s-s-d. If you have WIPE_TMP set to yes in conf.d/bootmisc you
    should disable find too.
    zsh and ksh do not work at this time.

    Networking support is currently being re-vamped also as it was heavily bash
    array based. As such, a new config format is available like so
    config_eth0="1.2.3.4/24 5.6.7.8/16"
    or like so
    config_eth0="'1.2.3.4 netmask 255.255.255.0' '5.6.7.8 netmask 255.255.0.0'"

    We will still support the old bash array format provided that /bin/sh IS
    a link it bash.

    ChangeLog for baselayout-1 can be found in our SVN repo.
1 # Copyright 2005-2007 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 _config_vars="$_config_vars plug_timeout"
5
6 netplugd_depend() {
7 program start /sbin/netplugd
8 after macnet rename
9 before interface
10 provide plug
11
12 # Prefer us to ifplugd
13 after ifplugd
14 }
15
16 netplugd_pre_start() {
17 local pidfile="/var/run/netplugd-${IFACE}.pid" timeout=
18
19 # We don't start netplug if we're being called from the background
20 ${IN_BACKGROUND} && return 0
21
22 _exists || return 0
23
24 # We need a valid MAC address
25 # It's a basic test to ensure it's not a virtual interface
26 if ! _get_mac_address >/dev/null 2>/dev/null ; then
27 vewarn "netplug only works on interfaces with a valid MAC address"
28 return 0
29 fi
30
31 # We don't work on bonded, bridges, tun/tap, vlan or wireless
32 for f in bond bridge tuntap vlan wireless ; do
33 if type "_is_${f}" >/dev/null 2>/dev/null ; then
34 if _is_${f} ; then
35 veinfo "netplug does not work with" "${f}"
36 return 0
37 fi
38 fi
39 done
40
41 ebegin "Starting netplug on" "${IFACE}"
42
43 # Mark the us as inactive so netplug can restart us
44 mark_service_inactive "${SVCNAME}"
45
46 # Start netplug
47 start-stop-daemon --start --exec /sbin/netplugd \
48 --pidfile "${pidfile}" \
49 -- -i "${IFACE}" -P -p "${pidfile}" -c /dev/null
50 eend "$?" || return 1
51
52 eindent
53
54 eval timeout=\$plug_timeout_${IFVAR}
55 [ -z "${timeout}" ] && timeout=-1
56 if [ ${timeout} -eq 0 ] ; then
57 ewarn "WARNING: infinite timeout set for" "${IFACE}" "to come up"
58 elif [ ${timeout} -lt 0 ] ; then
59 einfo "Backgrounding ..."
60 exit 1
61 fi
62
63 veinfo "Waiting for" "${IFACE}" "to be marked as started"
64
65 local i=0
66 while true ; do
67 if service_started "${SVCNAME}" ; then
68 _show_address
69 exit 0
70 fi
71 sleep 1
72 [ ${timeout} -eq 0 ]] && continue
73 i=$((${i} + 1))
74 [ ${i} -ge ${timeout} ] && break
75 done
76
77 eend 1 "Failed to configure" "${IFACE}" "in the background"
78 exit 1
79 }
80
81 netplugd_stop() {
82 ${IN_BACKGROUND} && return 0
83
84 local pidfile="/var/run/netplugd-${IFACE}.pid"
85 [ ! -e "${pidfile}" ] && return 0
86
87 ebegin "Stopping netplug on" "${IFACE}"
88 start-stop-daemon --stop --quiet --exec /sbin/netplugd \
89 --pidfile "${pidfile}"
90 eend $?
91 }
92
93 # vim: set ts=4 :

  ViewVC Help
Powered by ViewVC 1.1.20