From a7a05deb37b3db6aa3606f488467f621c40ce32d Mon Sep 17 00:00:00 2001 From: "Jan Alexander Steffens (heftig)" Date: Thu, 2 May 2013 07:03:12 +0200 Subject: lib/common.sh: Introduce locking helper functions Reduces code duplication. With makechrootpkg not calling mkarchroot anymore, the lock handover protocol is unneeded. arch-nspawn does not do any locking, so add protection to archbuild. --- lib/common.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'lib') diff --git a/lib/common.sh b/lib/common.sh index b39bbbc..9446ff5 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -130,3 +130,27 @@ get_full_version() { fi fi } + +## +# usage : lock( $fd, $file, $message ) +## +lock() { + eval "exec $1>"'"$2"' + if ! flock -n $1; then + stat_busy "$3" + flock $1 + stat_done + fi +} + +## +# usage : slock( $fd, $file, $message ) +## +slock() { + eval "exec $1>"'"$2"' + if ! flock -sn $1; then + stat_busy "$3" + flock -s $1 + stat_done + fi +} -- cgit v1.2.3-54-g00ecf