blob: 3700244d41ef3f2abec863eacfaefce193fff210 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#!/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
if [ "${use_md_swap}" = "1" ]; then
unit=$(mdconfig -a -t swap -s ${md_size})
newfs /dev/${unit} > /dev/null
chrootnum=$(echo ${unit} | sed 's,md,,')
chroot=${chrootdir}/${chrootnum}
mkdir -p ${chroot}/used 2>/dev/null || continue
# Need to make sure that used/ is also present after mounting the fresh md so as to not leave open any races
mount -o async /dev/${unit} ${chroot}/used
mkdir ${chroot}/used/used
touch ${chroot}/used/used/${pkgname}
umount ${chroot}/used
mount /dev/${unit} ${chroot}/
else
chrootnum=$(($chrootnum+1))
chroot=${chrootdir}/${chrootnum}
mkdir -p ${chroot} 2>/dev/null || continue
mkdir ${chroot}/used 2>/dev/null || continue
fi
touch ${chroot}/used/${pkgname}
touch ${chroot}/.notready
found=1
done
echo ${chroot}
|