From: Alexey Gladkov <gladkov.alexey@gmail.com> To: make-initrd@lists.altlinux.org Subject: [make-initrd] [PATCH 3/3] feature/network: Use flock-based locking Date: Wed, 17 May 2023 18:04:42 +0200 Message-ID: <9b76d23c4101232d96ccb4a9e7db004f60c239f4.1684332365.git.gladkov.alexey@gmail.com> (raw) In-Reply-To: <cover.1684332365.git.gladkov.alexey@gmail.com> Signed-off-by: Alexey Gladkov <gladkov.alexey@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
prev parent reply other threads:[~2023-05-17 16:04 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-05-17 16:04 [make-initrd] [PATCH 0/3] New locking functions based on flock utility Alexey Gladkov 2023-05-17 16:04 ` [make-initrd] [PATCH 1/3] runtime: Add " Alexey Gladkov 2023-05-17 16:04 ` [make-initrd] [PATCH 2/3] Rewrite console locking Alexey Gladkov 2023-05-17 16:04 ` Alexey Gladkov [this message]
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=9b76d23c4101232d96ccb4a9e7db004f60c239f4.1684332365.git.gladkov.alexey@gmail.com \ --to=gladkov.alexey@gmail.com \ --cc=make-initrd@lists.altlinux.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Make-initrd development discussion This inbox may be cloned and mirrored by anyone: git clone --mirror http://lore.altlinux.org/make-initrd/0 make-initrd/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 make-initrd make-initrd/ http://lore.altlinux.org/make-initrd \ make-initrd@lists.altlinux.org make-initrd@lists.altlinux.ru make-initrd@lists.altlinux.com public-inbox-index make-initrd Example config snippet for mirrors. Newsgroup available over NNTP: nntp://lore.altlinux.org/org.altlinux.lists.make-initrd AGPL code for this site: git clone https://public-inbox.org/public-inbox.git