blob: 00f27159dde483465fe4ffc9599e7bbe58f0dc43 (
plain) (
blame)
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
|
#!/bin/ash
wait_for_iface() {
local DEVICE=$1
local TIMEOUT=10
local state laststate current relax img in
local want=
local ret=1 # error
[ -n "$2" ] && TIMEOUT="$2"
echo -n "Waiting ${TIMEOUT}s for interface $DEVICE: "
TIMEOUT="$(( TIMEOUT * 2 ))"
if [ "$DEVICE" = "br0" ]; then
img="??-bridge"
else
img="??-nic"
fi
showicon --icon "/opt/openslx/icons/inactive/${img}.ppm"
# Some systems don't have operstate. Seems to be hardware dependent
[ -e "/sys/class/net/${DEVICE}/operstate" ] || sleep 1
[ -e "/sys/class/net/${DEVICE}/operstate" ] && want="up"
[ -e "/sys/class/net/${DEVICE}/carrier" ] && want="${want}1"
if [ -n "$want" ]; then
relax=$(( TIMEOUT / 3 ))
[ "$relax" -lt 8 ] && relax=8
current=0
while true; do
# check linkstate
state="$( cat "/sys/class/net/${DEVICE}/operstate" 2> /dev/null )"
state="${state}$( cat "/sys/class/net/${DEVICE}/carrier" 2> /dev/null )"
[ "$state" != "$laststate" ] && echo -n "[$state]"
laststate="$state"
if [ "$state" = "$want" ]; then
ret=0
break
fi
if [ "$current" -gt "$relax" ] && [ "$state" = "unknown1" ]; then
echo -n "better than nothing"
ret=0
break
fi
current=$(( current + 1 )) # don't wait forever, the pcnet iface of vmware will never be "up" although it's working
if [ "$current" -ge "$TIMEOUT" ];then
echo -n "TIMEOUT"
break
fi
# else
echo -n "."
usleep 500000
in=
[ "$(( current % 2 ))" = 0 ] && in="in"
showicon --icon "/opt/openslx/icons/${in}active/${img}.ppm" &
done
else
# we really don't have a operstate .. then just wait a sec and hope for the best.
sleep 1
echo -n "... no operstate or carrier, let's hope for the best..."
fi
echo
if [ "$ret" = 0 ]; then
showicon --icon "/opt/openslx/icons/active/${img}.ppm"
else
showicon --icon "/opt/openslx/icons/inactive/${img}.ppm"
fi
return "$ret"
}
true
|