File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -50,12 +50,17 @@ refresh)
5050start)
5151 register_networkd_reloader
5252 counter=0
53+ max_wait=3000 # 5 minute timeout to avoid infinite loop if sysfs node never appears
5354 while [ ! -e " /sys/class/net/${iface} " ]; do
5455 if (( counter % 1000 == 0 )) ; then
5556 debug " Waiting for sysfs node to exist for ${iface} (iteration $counter )"
5657 fi
5758 sleep 0.1
5859 (( counter++ ))
60+ if (( counter >= max_wait)) ; then
61+ error " Timed out waiting for sysfs node for ${iface} after $(( counter / 10 )) seconds"
62+ exit 1
63+ fi
5964 done
6065 debug " Starting configuration for $iface "
6166 debug /lib/systemd/systemd-networkd-wait-online -i " $iface "
Original file line number Diff line number Diff line change @@ -631,6 +631,18 @@ register_networkd_reloader() {
631631 local -r lockfile=" ${lockdir} /${iface} "
632632 local old_opts=$-
633633
634+ # If the existing lock owner is no longer alive, remove the stale lockfile
635+ # so subsequent invocations don't spin for up to 1000 seconds waiting on a
636+ # process that will never release it.
637+ if [ -f " ${lockfile} " ]; then
638+ local existing_pid
639+ existing_pid=$( cat " ${lockfile} " 2> /dev/null)
640+ if [ -n " $existing_pid " ] && ! kill -0 " $existing_pid " 2> /dev/null; then
641+ debug " Removing stale lock from dead process $existing_pid for ${iface} "
642+ rm -f " ${lockfile} "
643+ fi
644+ fi
645+
634646 # Disable -o errexit in the following block so we can capture
635647 # nonzero exit codes from a redirect without considering them
636648 # fatal errors
You can’t perform that action at this time.
0 commit comments