Files
ports/Tools/portbuild/scripts/claim-chroot
T
Kris Kennaway 2bec66d639 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.
2004-07-14 10:44:36 +00:00

53 lines
1.0 KiB
Bash
Executable File

#!/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}