diff options
author | kris <kris@FreeBSD.org> | 2004-07-14 18:44:36 +0800 |
---|---|---|
committer | kris <kris@FreeBSD.org> | 2004-07-14 18:44:36 +0800 |
commit | 028e45e4d8bc706488498f901a24eedfaa53b1cb (patch) | |
tree | a2902890362f7dce3990586effaef9884a7ce254 /Tools | |
parent | 980b2e875a5775087970aa73822820770f29948c (diff) | |
download | freebsd-ports-gnome-028e45e4d8bc706488498f901a24eedfaa53b1cb.tar.gz freebsd-ports-gnome-028e45e4d8bc706488498f901a24eedfaa53b1cb.tar.zst freebsd-ports-gnome-028e45e4d8bc706488498f901a24eedfaa53b1cb.zip |
Atomically claim an unused chroot directory. The previous algorithm
was not atomic and could have ended up with two port builds trying to use
the same chroot. Report the claimed directory back to the caller.
Diffstat (limited to 'Tools')
-rwxr-xr-x | Tools/portbuild/scripts/claim-chroot | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/Tools/portbuild/scripts/claim-chroot b/Tools/portbuild/scripts/claim-chroot new file mode 100755 index 000000000000..fae7e86c165c --- /dev/null +++ b/Tools/portbuild/scripts/claim-chroot @@ -0,0 +1,52 @@ +#!/bin/sh + +# usage: claim-chroot ${arch} ${branch} ${pkgname} + +# configurable variables +pb=/var/portbuild + +arch=$1 +shift + +. ${pb}/${arch}/portbuild.conf +. ${pb}/${arch}/portbuild.$(hostname) +. ${pb}/scripts/buildenv + +buildroot=${scratchdir} +error=0 + +branch=$1 +shift + +buildenv ${pb} ${arch} ${branch} + +pkgname=$(basename $1 ${PKGSUFFIX}) + +chrootdir=${buildroot}/${branch}/chroot + +found=0 +# Look for pre-existing chroot directories that are populated and unused +for dir in ${chrootdir}/*; do + if [ -f ${dir}/.ready -a -d ${dir}/tmp ]; then + # Atomically claim the directory + mkdir ${dir}/used 2>/dev/null || continue + touch ${dir}/used/${pkgname} + found=1 + chroot=${dir} + break + fi +done + +chrootnum=$$ +# If we didn't find a pre-existing directory, create and claim a new one. +while [ ${found} != 1 ]; do + chrootnum=$((chrootnum+1)) + chroot=${chrootdir}/${chrootnum} + mkdir -p ${chroot} 2>/dev/null || continue + mkdir ${chroot}/used 2>/dev/null || continue + touch ${chroot}/used/${pkgname} + touch ${chroot}/.notready + found=1 +done + +echo ${chroot} |