Skip to content

Commit 8b36229

Browse files
committed
ifupdown2-hotplug: adapt script for ifupdown2 #213
Fix: #213 Fix: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=988050
1 parent 03f1b1f commit 8b36229

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

debian/ifupdown2-hotplug

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ else
1313
unset LOGGER
1414
fi
1515

16+
LOCKFILE=/run/network/.lock
17+
1618
# for diagnostics
1719
if [ -t 1 -a -z "$LOGGER" ] || [ ! -e '/dev/log' ]; then
1820
mesg() {
@@ -49,19 +51,21 @@ wait_for_interface() {
4951

5052
net_ifup() {
5153

52-
# exit if the interface is not configured as allow-hotplug
53-
TARGET_IFACE=$(/sbin/ifquery --allow hotplug -l "$INTERFACE" || true)
54-
if [ -z "$TARGET_IFACE" ]; then
54+
# exit if the interface is not configured as allow-hotplug (querying does not require a lock)
55+
if ! $(/sbin/ifquery --allow=hotplug -l 2>/dev/null | grep -w -q "^$INTERFACE$"); then
5556
exit 0
5657
fi
5758

5859
if [ -d /run/systemd/system ]; then
59-
exec systemctl --no-block start $(systemd-escape --template [email protected] $TARGET_IFACE)
60+
exec systemctl --no-block start $(systemd-escape --template [email protected] $INTERFACE)
6061
fi
6162

62-
wait_for_interface lo
63-
64-
exec ifup --allow=hotplug $INTERFACE
63+
# Take the lock and wait for lo before exec ifup.
64+
(
65+
flock 9
66+
wait_for_interface lo
67+
exec ifup $INTERFACE -L 9
68+
) 9>$LOCKFILE
6569
}
6670

6771
net_ifdown() {
@@ -72,7 +76,16 @@ net_ifdown() {
7276
exit 0
7377
fi
7478

75-
exec ifdown --allow=hotplug $INTERFACE
79+
# exit if the interface is not configured as allow-hotplug (querying does not require a lock)
80+
if ! $(/sbin/ifquery --allow=hotplug -l 2>/dev/null | grep -w -q "^$INTERFACE$"); then
81+
exit 0
82+
fi
83+
84+
# Take the lock and exec ifdown.
85+
(
86+
flock 9
87+
exec ifdown $INTERFACE -L 9
88+
) 9>$LOCKFILE
7689
}
7790

7891
do_everything() {

0 commit comments

Comments
 (0)