summaryrefslogtreecommitdiff
path: root/Tools
diff options
context:
space:
mode:
authorKris Kennaway <kris@FreeBSD.org>2005-02-12 03:38:08 +0000
committerKris Kennaway <kris@FreeBSD.org>2005-02-12 03:38:08 +0000
commitccb8be3838517bfa35a23d4ba948c610c9907ced (patch)
treed2b957b40c6c768b6d22d439b0c4353acde3c758 /Tools
parent4e40e823b4c5ec679a4331dc1e5ae2fd50e4b115 (diff)
downloadfreebsd-ports-ccb8be3838517bfa35a23d4ba948c610c9907ced.zip
* 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)
Diffstat (limited to 'Tools')
-rwxr-xr-xTools/portbuild/scripts/clean-chroot51
1 files changed, 44 insertions, 7 deletions
diff --git a/Tools/portbuild/scripts/clean-chroot b/Tools/portbuild/scripts/clean-chroot
index 3911470fd284..eba3889f8db8 100755
--- a/Tools/portbuild/scripts/clean-chroot
+++ b/Tools/portbuild/scripts/clean-chroot
@@ -1,5 +1,37 @@
#!/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
branch=$2
chroot=$3
@@ -8,6 +40,10 @@ noclean=$4
# directories to clean
cleandirs="/usr/local /usr/X11R6 /compat /var/db/pkg"
+if [ ! -d "${chroot}" ]; then
+ exit 0
+fi
+
if [ `realpath ${chroot}` = "/" ]; then
# Don't spam the root file system if something has gone wrong!
exit 1
@@ -16,13 +52,14 @@ fi
#umount ${chroot}/proc
if [ ${arch} = "i386" ]; then
- chroot ${chroot} umount -f /compat/linux/proc
+ cleanup_mount ${chroot} /compat/linux/proc
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
-umount -f ${chroot}/usr/opt/doc 2> /dev/null
-umount -f ${chroot}/usr/src 2> /dev/null
-umount -f ${chroot}/dev 2> /dev/null
+#kill_procs ${chroot}
if [ $noclean = 0 ]; then
rm -rf ${chroot}/tmp/*
@@ -32,9 +69,9 @@ if [ $noclean = 0 ]; then
rm -rf ${chroot}${dir} >/dev/null 2>&1
fi
done
- chroot ${chroot} /sbin/ldconfig -R
+ test -x ${chroot}/sbin/ldconfig && chroot ${chroot} /sbin/ldconfig -R
if [ ${arch} = "i386" ]; then
- chroot ${chroot} /sbin/ldconfig -aout -R
+ test -x ${chroot}/sbin/ldconfig && chroot ${chroot} /sbin/ldconfig -aout -R
fi
rm -rf ${chroot}/var/db/pkg/*
rm -rf ${chroot}/used