File: net.agent

package info (click to toggle)
udev 164-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 4,336 kB
  • ctags: 1,738
  • sloc: ansic: 18,516; sh: 11,378; perl: 1,725; xml: 1,286; makefile: 692; python: 34
file content (105 lines) | stat: -rw-r--r-- 2,066 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/sh -e
#
# run /sbin/{ifup,ifdown} with the --allow=hotplug option.
#

. /lib/udev/hotplug.functions

if [ -z "$INTERFACE" ]; then
    mesg "Bad net.agent invocation: \$INTERFACE is not set"
    exit 1
fi

check_program() {
    [ -x $1 ] && return 0

    mesg "ERROR: $1 not found. You need to install the ifupdown package."
    mesg "net.agent $ACTION event for $INTERFACE not handled."
    exit 1
}

wait_for_interface() {
    local interface=$1

    while :; do
	local state="$(cat /sys/class/net/$interface/operstate 2>/dev/null || true)"
	if [ "$state" != down ]; then
		return 0
	fi
	sleep 1
    done
}

net_ifup() {
    check_program /sbin/ifup

    if grep -q '^auto[[:space:]].*\<'"$INTERFACE"'\>' \
	    /etc/network/interfaces; then
	# this $INTERFACE is marked as "auto"
	IFUPARG='\('$INTERFACE'\|-a\|--all\)'
    else
	IFUPARG=$INTERFACE
    fi

    if ps -C ifup ho args | grep -q "$IFUPARG"; then
        debug_mesg "Already ifup-ing interface $INTERFACE"
	exit 0
    fi

    wait_for_interface lo
    if [ -e /bin/systemctl ]; then
      wait_for_file /dev/log
    fi

    exec ifup --allow=hotplug $INTERFACE
}

net_ifdown() {
    check_program /sbin/ifdown

    if ps -C ifdown ho args | grep -q $INTERFACE; then
	debug_mesg "Already ifdown-ing interface $INTERFACE"
	exit 0
    fi

    exec ifdown --allow=hotplug $INTERFACE
}

do_everything() {

case "$ACTION" in
    add)
    # these interfaces generate hotplug events *after* they are brought up
    case $INTERFACE in
	ppp*|ippp*|isdn*|plip*|lo|irda*|ipsec*)
	exit 0 ;;
    esac

    net_ifup
    ;;

    remove)
    # the pppd persist option may have been used, so it should not be killed
    case $INTERFACE in
	ppp*)
	exit 0 ;;
    esac

    net_ifdown
    ;;

    *)
    debug_mesg "NET $ACTION event not supported"
    exit 1
    ;;
esac

}

# When udev_log="debug" stdout and stderr are pipes connected to udevd.
# They need to be closed or udevd will wait for this process which will
# deadlock with udevsettle until the timeout.
do_everything > /dev/null 2> /dev/null &

exit 0