From 9e2b1785274143735ea356426cccb0bf2f26c00a Mon Sep 17 00:00:00 2001 From: Kris Kennaway Date: Sat, 12 Feb 2005 03:38:37 +0000 Subject: 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. --- Tools/portbuild/scripts/cleanup-chroots | 36 ++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'Tools') 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 -- cgit v1.2.3