From e9836b6b2afa70f22d305509593b375543b20ba6 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 25 Nov 2012 20:05:09 -0500 Subject: Use common functions to handle file locking * lib/common.sh: implement - lock_open_write() - lock_open_read() - lock_close() * archbuild.in, makechrootpkg.in, mkarchroot.in: use said functions This has two benefits: 1. All programs using these methods gain the ability to inherit locks, something that only mkarchroot could do before. This allows the commands to be more compos-able. 2. It is more readable. File locking isn't obvious. --- mkarchroot.in | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'mkarchroot.in') diff --git a/mkarchroot.in b/mkarchroot.in index 76ad840..022943e 100644 --- a/mkarchroot.in +++ b/mkarchroot.in @@ -183,17 +183,7 @@ trap_chroot_umount () { } chroot_lock () { - # Only reopen the FD if it wasn't handed to us - if [[ $(readlink -f /dev/fd/9) != "${working_dir}.lock" ]]; then - exec 9>"${working_dir}.lock" - fi - - # Lock the chroot. Take note of the FD number. - if ! flock -n 9; then - stat_busy "Locking chroot" - flock 9 - stat_done - fi + lock_open_write 9 "${working_dir}.lock" "Locking chroot"u } chroot_run() { -- cgit v1.2.3-70-g09d2