commit c4e05839dc9314aa764c433c6eec5e52a868a8df
parent 07e788749f5e3602c450a4b74e039988833dbbde
Author: Morel BĂ©renger <berengermorel76@gmail.com>
Date: Sun, 3 Jan 2021 14:51:46 +0100
generic: bb-udhcpc no longer floods if cable not plugged
Diffstat:
3 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/templates/generic/packages/base.list b/templates/generic/packages/base.list
@@ -1 +1 @@
-runit-init,busybox-static,linux-image-amd64,
+runit-init,busybox-static,linux-image-amd64,ethtool,
diff --git a/templates/generic/root/etc/sv/bb-udhcpc/finish b/templates/generic/root/etc/sv/bb-udhcpc/finish
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+. /etc/runit/common
+
+# no checks on valid IFACE, we already did that
+IFACE="$(echo ${SVNAME} | cut -f2 -d-)"
+
+EXIT_CODE=$1
+STATUS=$2
+SLEEP=60
+
+if test "$EXIT_CODE" = "1"
+then
+ test "$VERBOSE" = "yes" && echo unplugged, sleeping $SLEEP
+ sleep $SLEEP
+fi
diff --git a/templates/generic/root/etc/sv/bb-udhcpc/run b/templates/generic/root/etc/sv/bb-udhcpc/run
@@ -1,5 +1,13 @@
#!/bin/sh
+#this script runs busybox's udhcpc if preconditions are ok.
+#return=preconditions:explanations
+#1=cable is plugged:
+# if no cable, just return and sleep.
+# Automatic handling would be better, but it's hard to
+# find real doc on how kernel works there (no, I don't
+# like udev).
+
. /etc/runit/common
IFACE="$(echo ${SVNAME} | cut -f2 -d-)"
@@ -7,5 +15,12 @@ IFACE="$(echo ${SVNAME} | cut -f2 -d-)"
test -n "$IFACE" || badconf "Unable to retrieve interface name from \"$SVNAME\""
ip link show "$IFACE" > /dev/null || badconf "Unknown IFACE"
+#try to detect plugged cable before trying using the NIC
+#default to true, so if detection broken, try anyway
+TRY=yes
+test -e /sbin/ethtool $IFACE | grep -q 'Link detected: no' && TRY=no
+
+test "$TRY" = "no" && return 1
+
echo "Starting udhcpc on $IFACE..."
exec udhcpc -i ${IFACE} -f -R -n