[make-initrd] [PATCH 3/3] feature/network: Use flock-based locking
Alexey Gladkov
gladkov.alexey at gmail.com
Wed May 17 19:04:42 MSK 2023
Signed-off-by: Alexey Gladkov <gladkov.alexey at gmail.com>
---
features/network/data/lib/network/config | 8 --------
features/network/data/lib/network/hostname | 10 +++-------
features/network/data/lib/network/resolvconf | 10 +++-------
features/network/data/lib/network/udhcpc4.script | 12 ++++++------
4 files changed, 12 insertions(+), 28 deletions(-)
diff --git a/features/network/data/lib/network/config b/features/network/data/lib/network/config
index c3a8dbb1..418b03b6 100755
--- a/features/network/data/lib/network/config
+++ b/features/network/data/lib/network/config
@@ -1,14 +1,6 @@
#!/bin/bash -efu
. shell-error
-
-lock="/tmp/$PROG.lock"
-while ! mkdir -- "$lock" >/dev/null 2>&1; do
- sleep 0.1
-done
-unlock() { rmdir "$lock"; }
-trap unlock EXIT
-
. network-sh-functions
PROG="$PROG: $NET_IF"
diff --git a/features/network/data/lib/network/hostname b/features/network/data/lib/network/hostname
index 1160fba0..3597a495 100755
--- a/features/network/data/lib/network/hostname
+++ b/features/network/data/lib/network/hostname
@@ -1,18 +1,12 @@
#!/bin/bash -efu
. shell-error
+. shell-locks
. network-sh-functions
[ "$NET_EV_ACTION" = update ] ||
exit 0
-lock="/tmp/$PROG.lock"
-while ! mkdir -- "$lock" >/dev/null 2>&1; do
- sleep 0.1
-done
-unlock() { rmdir "$lock"; }
-trap unlock EXIT
-
PROG="$PROG: $NET_IF"
message_time=1
@@ -20,6 +14,8 @@ get_iface_confdir &&
[ -f "$confdir/hostname" ] ||
exit 0
+fd_lock 90 "$0"
+
name=
read -r name < "$confdir/hostname" ||:
diff --git a/features/network/data/lib/network/resolvconf b/features/network/data/lib/network/resolvconf
index e6e14602..67ccb8ab 100755
--- a/features/network/data/lib/network/resolvconf
+++ b/features/network/data/lib/network/resolvconf
@@ -1,18 +1,12 @@
#!/bin/bash -efu
. shell-error
+. shell-locks
. network-sh-functions
[ "$NET_EV_ACTION" = update ] ||
exit 0
-lock="/tmp/$PROG.lock"
-while ! mkdir -- "$lock" >/dev/null 2>&1; do
- sleep 0.1
-done
-unlock() { rmdir "$lock"; }
-trap unlock EXIT
-
PROG="$PROG: $NET_IF"
message_time=1
@@ -20,6 +14,8 @@ get_iface_confdir &&
[ -f "$confdir/resolv.conf" ] ||
exit 0
+fd_lock 90 "$0"
+
message "write resolv.conf"
tmp="$(mktemp "/etc/resolv.conf.XXXXXX")"
diff --git a/features/network/data/lib/network/udhcpc4.script b/features/network/data/lib/network/udhcpc4.script
index dcb1f74c..bd1b4779 100755
--- a/features/network/data/lib/network/udhcpc4.script
+++ b/features/network/data/lib/network/udhcpc4.script
@@ -1,5 +1,7 @@
#!/bin/bash -efu
+. shell-locks
+
STATE="$1"
PROG="${0##*/}"
@@ -9,11 +11,9 @@ V="${CMDNAME##udhcpc}"
INTERFACE="${interface-}"
lock="/tmp/$CMDNAME.$INTERFACE.lock"
-while ! mkdir -- "$lock" >/dev/null 2>&1; do
- sleep 0.1
-done
-unlock() { rmdir "$lock"; }
-trap unlock EXIT
+[ -d "$lock" ] || mkdir -p -- "$lock"
+
+fd_lock 90 "$lock"
logfile=$(
. /.initrd/initenv
@@ -148,4 +148,4 @@ case "$STATE" in
*)
exit 0
;;
-esac
+esac 90<&-
--
2.33.8
More information about the Make-initrd
mailing list