summaryrefslogtreecommitdiff
path: root/Tools
diff options
context:
space:
mode:
authorKris Kennaway <kris@FreeBSD.org>2005-02-12 03:38:37 +0000
committerKris Kennaway <kris@FreeBSD.org>2005-02-12 03:38:37 +0000
commit9e2b1785274143735ea356426cccb0bf2f26c00a (patch)
tree225e7bda13410ba630cd694963e2ce81c203bab2 /Tools
parent* Instead of using umount -f to unmount things, first use fstat to (diff)
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.
Notes
Notes: svn path=/head/; revision=128584
Diffstat (limited to 'Tools')
-rwxr-xr-xTools/portbuild/scripts/cleanup-chroots36
1 files changed, 35 insertions, 1 deletions
diff --git a/Tools/portbuild/scripts/cleanup-chroots b/Tools/portbuild/scripts/cleanup-chroots
index 421ef3e84406..4254318c9e7f 100755
--- a/Tools/portbuild/scripts/cleanup-chroots
+++ b/Tools/portbuild/scripts/cleanup-chroots
@@ -5,6 +5,38 @@
# in 24 hours (corresponding to port builds that have timed out or shut down uncleanly)
# and prunes them to reclaim space.
+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
+}
+
pb=/var/portbuild
arch=$(cat /etc/arch)
@@ -37,7 +69,9 @@ fi
for i in ${old2}; do
mounts=$(mount | grep $i | awk '{print $3}')
if [ ! -z "${mounts}" ]; then
- umount -f ${mounts}
+ for j in ${mounts}; do
+ umount ${j} || cleanup_mount ${j}
+ done
fi
done