summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJan Alexander Steffens (heftig) <jan.steffens@gmail.com>2013-05-02 07:03:12 +0200
committerJan Alexander Steffens (heftig) <jan.steffens@gmail.com>2013-05-03 04:34:29 +0200
commita7a05deb37b3db6aa3606f488467f621c40ce32d (patch)
tree3091e3cdfc4abb0c73c9199d5c54b6fdfbe5f1d4 /lib
parent0e98bd8c485b2c55c3971823f99a13c41b1ed696 (diff)
downloaddevtools32-a7a05deb37b3db6aa3606f488467f621c40ce32d.tar.xz
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/common.sh24
1 files changed, 24 insertions, 0 deletions
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
+}