* Instead of using umount -f to unmount things, first use fstat to

look for processes holding open references within the FS and kill
them, then use regular umount.  This is necessary now that devfs
cannot be force-unmounted, and has the benefit that processes can't
hang around holding references to files between port builds.

* Reduce possibility for error by testing for presence of executable
ldconfig inside the chroot before attempting to run it (e.g. it may not
be there if the chroot was not completely initialized)
This commit is contained in:
Kris Kennaway 2005-02-12 03:38:08 +00:00
parent 4e40e823b4
commit ccb8be3838
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=128583

View File

@ -1,5 +1,37 @@
#!/bin/sh #!/bin/sh
kill_procs()
{
dir=$1
pids="XXX"
while [ ! -z "${pids}" ]; do
pids=$(fstat -f "$dir" | tail +2 | awk '{print $3}' | sort -u)
if [ ! -z "${pids}" ]; then
echo "Killing off pids in ${dir}"
ps -p $pids
kill -KILL ${pids} 2> /dev/null
sleep 2
fi
done
}
cleanup_mount() {
chroot=$1
mount=$2
if [ -d ${chroot}${mount} ]; then
mdir=$(fstat -f ${chroot}${mount} | head -2 | tail -1 | awk '{print $5}')
if [ "${mdir}" = "MOUNT" ]; then
umount ${chroot}${mount} || echo "Cleanup of ${chroot}${mount} failed!"
fi
if [ "${mdir}" = "${chroot}${mount}" ]; then
kill_procs ${chroot}${mount}
umount ${chroot}${mount} || echo "Cleanup of ${chroot}${mount} failed!"
fi
fi
}
arch=$1 arch=$1
branch=$2 branch=$2
chroot=$3 chroot=$3
@ -8,6 +40,10 @@ noclean=$4
# directories to clean # directories to clean
cleandirs="/usr/local /usr/X11R6 /compat /var/db/pkg" cleandirs="/usr/local /usr/X11R6 /compat /var/db/pkg"
if [ ! -d "${chroot}" ]; then
exit 0
fi
if [ `realpath ${chroot}` = "/" ]; then if [ `realpath ${chroot}` = "/" ]; then
# Don't spam the root file system if something has gone wrong! # Don't spam the root file system if something has gone wrong!
exit 1 exit 1
@ -16,13 +52,14 @@ fi
#umount ${chroot}/proc #umount ${chroot}/proc
if [ ${arch} = "i386" ]; then if [ ${arch} = "i386" ]; then
chroot ${chroot} umount -f /compat/linux/proc cleanup_mount ${chroot} /compat/linux/proc
fi fi
for i in /a/ports /usr/opt/doc /usr/src /dev; do
cleanup_mount ${chroot} ${i}
done
umount -f ${chroot}/a/ports 2> /dev/null #kill_procs ${chroot}
umount -f ${chroot}/usr/opt/doc 2> /dev/null
umount -f ${chroot}/usr/src 2> /dev/null
umount -f ${chroot}/dev 2> /dev/null
if [ $noclean = 0 ]; then if [ $noclean = 0 ]; then
rm -rf ${chroot}/tmp/* rm -rf ${chroot}/tmp/*
@ -32,9 +69,9 @@ if [ $noclean = 0 ]; then
rm -rf ${chroot}${dir} >/dev/null 2>&1 rm -rf ${chroot}${dir} >/dev/null 2>&1
fi fi
done done
chroot ${chroot} /sbin/ldconfig -R test -x ${chroot}/sbin/ldconfig && chroot ${chroot} /sbin/ldconfig -R
if [ ${arch} = "i386" ]; then if [ ${arch} = "i386" ]; then
chroot ${chroot} /sbin/ldconfig -aout -R test -x ${chroot}/sbin/ldconfig && chroot ${chroot} /sbin/ldconfig -aout -R
fi fi
rm -rf ${chroot}/var/db/pkg/* rm -rf ${chroot}/var/db/pkg/*
rm -rf ${chroot}/used rm -rf ${chroot}/used