diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2012-11-26 01:33:06 -0500 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2012-11-26 01:33:06 -0500 |
commit | 51da0a96df75bb05469687be346ea6aa9c3bfd40 (patch) | |
tree | c9dc6e3d27f27c5f174ca849538cefe31f7c32ef | |
parent | f6bc9735151836a83e10c230aa77d0da7dc7b36a (diff) | |
parent | bc7c9c19f00a161edce3a35c51d8164baee35f40 (diff) |
Merge branch 'master' into clean
Conflicts:
archbuild.in
-rw-r--r-- | lib/common.sh | 49 | ||||
-rw-r--r-- | makechrootpkg.in | 19 | ||||
-rw-r--r-- | mkarchroot.in | 12 |
3 files changed, 54 insertions, 26 deletions
diff --git a/lib/common.sh b/lib/common.sh index b39bbbc..5204091 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -104,6 +104,55 @@ in_array() { } ## +# usage : lock_open_write( $fd, $path, $wait_message ) +## +lock_open_write() { + local fd=$1 + local path=$2 + local msg=$3 + + # Only reopen the FD if it wasn't handed to us + if [[ $(readlink -f /dev/fd/$fd) != "${path}.lock" ]]; then + eval "exec $fd>${path}.lock" + fi + + if ! flock -n $fd; then + stat_busy "$msg" + flock $fd + stat_done + fi +} + +## +# usage : lock_open_read( $fd, $path, $wait_message ) +## +lock_open_read() { + local fd=$1 + local path=$2 + local msg=$3 + + # Only reopen the FD if it wasn't handed to us + if [[ $(readlink -f /dev/fd/$fd) != "${path}.lock" ]]; then + eval "exec $fd>${path}.lock" + fi + + if ! flock -sn $fd; then + stat_busy "$msg" + flock -s $fd + stat_done + fi +} + + +## +# usage : lock_close( $fd ) +## +lock_close() { + local fd=$1 + eval "exec $fd>&-" +} + +## # usage : get_full_version( [$pkgname] ) # return : full version spec, including epoch (if necessary), pkgver, pkgrel ## diff --git a/makechrootpkg.in b/makechrootpkg.in index 6c0b013..b635432 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 @@ -267,7 +256,7 @@ cat >"$copydir/chrootbuild" <<EOF export HOME=/build cd /build -sudo -u nobody makepkg $makepkg_args || touch BUILD_FAILED +sudo -u nobody ${MAKEPKG:-makepkg} $makepkg_args || touch BUILD_FAILED [[ -f BUILD_FAILED ]] && exit 1 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() { |