Tiny Core Linux
Tiny Core Base => TCB Q&A Forum => Topic started by: funguy on March 11, 2012, 06:03:37 PM
-
I noticed that when I boot TCL sometimes udhcpc isn't finished and i have to wait. After I wait everything is fine. Is there a kernel boot option to wait for udhcpd before startx continues. If not what command other than sleep can I run to wait for the udhcpc to complete assigning ips before it runs the next command that needs network up first?
-
I personally would probably not use an unconditional 'sleep' but rather something like
while [ -z "$( ifconfig eth0 | grep 'inet addr' )" ] ; do sleep 1 ; done
to wait until the NIC in question shows an IP address. Any call to an application that requires a working NIC can follow afterwards.
-
That looks good but imagine a server with say 6 nics and other machines with just 1 nic. I need to account for all "present" nics. It isn't always eth0. Any additional ideas?
-
Hi funguy
You could loop through the /sys/class/net directory.
Skip the dummy and lo entries.
Check the carrier file on the remaining entries. When the NIC comes up, it will contain a 1, when it's down, the file is empty.
-
do you have code for that loop? I just wish there was a way to tell by the original process, or undo the seperated dhcp method that allows it to fork to the background if needed.
-
Hi funguy
I think this should work:
#!/bin/sh
NicCount=0
Timeout=10
for NICS in `ls -1 /sys/class/net`
do
[ "$NICS" = "dummy0" ] && continue
[ "$NICS" = "lo" ] && continue
let "NicCount += 1"
/bin/rm -f /tmp/$NICS.found
done
while [ $Timeout -gt 0 ]
do
for NICS in `ls -1 /sys/class/net`
do
[ "$NICS" = "dummy0" ] && continue
[ "$NICS" = "lo" ] && continue
if [ ! -e /tmp/$NICS.found ]
then
if [ `/bin/grep 1 /sys/class/net/$NICS/carrier` ]
then
touch /tmp/$NICS.found
let "NicCount -= 1"
fi
fi
done
[ $NicCount -le 0 ] && break
sleep 1
let "Timeout -= 1"
done
echo $NicCount
The script will continue to execute until all the network interfaces are brought up. Should any interfaces fail
to come up, there is a 10 second timeout to terminate the loop. If all the interfaces were brought up, it
returns 0, otherwise it returns the number of interfaces that failed to come up.
-
It's considered bad practise to have more than one NIC use dhcp, you know ;)
-
Tested and minor issues. Eth0 unplugged and eth1 ready leads to 10 second pause during testing. Can the script be modded to skip no-link ethernets?
-
Hi funguy
I don't know how you would tell the difference between a link that has not yet been brought up and one that
is not connected. You can modify Timeout=10 to Timeout=5 or to whatever you want, I just pulled that
number out of thin air.
-
I don't know how you would tell the difference between a link that has not yet been brought up and one that
is not connected.
You can detect whether line is connected or not with ethtool:
[root@zero ~]# ethtool eth0
Settings for eth0:
Supported ports: [ MII ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Advertised pause frame use: No
Advertised auto-negotiation: Yes
Speed: 100Mb/s
Duplex: Full
Port: MII
PHYAD: 1
Transceiver: external
Auto-negotiation: on
Supports Wake-on: g
Wake-on: d
Link detected: yes
[root@zero ~]#
-
Hi bmarkus
All I get is this:
[tc@box:~$ sudo ethtool eth0
Settings for eth0:
Supports Wake-on: d
Wake-on: d
tc@box:~$ /quote]