summaryrefslogtreecommitdiff
path: root/makechrootpkg.in
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2012-11-25 20:05:09 -0500
committerLuke Shumaker <LukeShu@sbcglobal.net>2012-11-25 20:28:14 -0500
commite9836b6b2afa70f22d305509593b375543b20ba6 (patch)
tree9695c79202bb58c4014033f98a0021790f49817e /makechrootpkg.in
parent2343d5c3c034c2597a034f5a5de9373d7e076e60 (diff)
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.
Diffstat (limited to 'makechrootpkg.in')
-rw-r--r--makechrootpkg.in17
1 files changed, 3 insertions, 14 deletions
diff --git a/makechrootpkg.in b/makechrootpkg.in
index 6c0b013..f3333ca 100644
--- a/makechrootpkg.in
+++ b/makechrootpkg.in
@@ -114,23 +114,12 @@ umask 0022
# Lock the chroot we want to use. We'll keep this lock until we exit.
# Note this is the same FD number as in mkarchroot
-exec 9>"$copydir.lock"
-if ! flock -n 9; then
- stat_busy "Locking chroot copy '$copy'"
- flock 9
- stat_done
-fi
+lock_open_write 9 "$copydir.lock" "Locking chroot copy '$copy'"
if [[ ! -d $copydir ]] || $clean_first; then
# Get a read lock on the root chroot to make
# sure we don't clone a half-updated chroot
- exec 8>"$chrootdir/root.lock"
-
- if ! flock -sn 8; then
- stat_busy "Locking clean chroot"
- flock -s 8
- stat_done
- fi
+ lock_open_read 8 "$chrootdir/root.lock" "Locking clean chroot"
stat_busy 'Creating clean working copy'
use_rsync=false
@@ -149,7 +138,7 @@ if [[ ! -d $copydir ]] || $clean_first; then
stat_done
# Drop the read lock again
- exec 8>&-
+ lock_close 8
fi
if [[ -n $install_pkg ]]; then