meta-google: google-usb-network: Retry renaming device
Sometimes our device rename races with networkd bringing it up. Try a
few times to rename until we succeed.
Change-Id: I9eee947bc0a38c29839efe8e5e56a14c73b16b2c
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/meta-google/recipes-google/networking/google-usb-network/usb_network.sh b/meta-google/recipes-google/networking/google-usb-network/usb_network.sh
index ba271b7..ec9c2cf 100755
--- a/meta-google/recipes-google/networking/google-usb-network/usb_network.sh
+++ b/meta-google/recipes-google/networking/google-usb-network/usb_network.sh
@@ -95,13 +95,16 @@
ln -s "${func_dir}" "${config_dir}" || return
echo "${BIND_DEVICE}" >${gadget_dir}/UDC || return
- local ifname
- ifname="$(<"${func_dir}"/ifname)" || return
- if [ "${IFACE_NAME}" != "$ifname" ]; then
- # We don't care if downing the interface fails, only the rename
- ip link set dev "$ifname" down || true
- ip link set dev "$ifname" name "${IFACE_NAME}" || return
- fi
+ # Try to reconfigure a few times in case we race with systemd-networkd
+ local start=$SECONDS
+ while (( SECONDS - start < 5 )); do
+ local ifname
+ ifname="$(<"${func_dir}"/ifname)" || return
+ [ "${IFACE_NAME}" = "$ifname" ] && break
+ ip link set dev "$ifname" down && \
+ ip link set dev "$ifname" name "${IFACE_NAME}" && break
+ sleep 1
+ done
ip link set dev "$IFACE_NAME" up || return
}