#! /bin/sh /usr/share/dpatch/dpatch-run ## 12_vnamespace_cleanup.dpatch by Micah Anderson > ## ## All lines beginning with `## DP:' are a description of the patch. ## DP: No description. @DPATCH@ diff -urNad trunk~/doc/configuration.xml trunk/doc/configuration.xml --- trunk~/doc/configuration.xml 2006-03-20 08:16:46.000000000 -0500 +++ trunk/doc/configuration.xml 2006-04-05 23:18:43.000000000 -0400 @@ -37,6 +37,14 @@ + + +Enable namespace cleanup globally. It can be overridden for a single vserver +by setting the nonamespace-cleanup flag +there. + + + Path of the vserver run reverse directory. This directory contains @@ -344,6 +352,19 @@ + + +Overrides the global namespace-cleanup flag and disables +namespace cleanup for the current vserver. + + + + + +Enable namespace cleanup for the current vserver. + + + [experimental; name is subject of possible change] Contains the diff -urNad trunk~/scripts/functions trunk/scripts/functions --- trunk~/scripts/functions 2006-03-20 08:16:45.000000000 -0500 +++ trunk/scripts/functions 2006-04-05 23:18:43.000000000 -0400 @@ -480,6 +480,18 @@ -e "$cfgdir"/nonamespace } +function isNamespaceCleanup +{ + local cfgdir + + $_VSERVER_INFO - FEATURE namespace || return 1 + cfgdir=$($_VSERVER_INFO "$1" CFGDIR) || return 1 + test -e "$cfgdir"/nonamespace-cleanup && return 1 + test -e "$__CONFDIR"/.defaults/namespace-cleanup -o \ + -e "$cfgdir"/namespace-cleanup && return 0 + return 1 +} + ## Usage: getAllVservers [*] function getAllVservers { diff -urNad trunk~/scripts/vserver.functions trunk/scripts/vserver.functions --- trunk~/scripts/vserver.functions 2006-03-20 08:16:45.000000000 -0500 +++ trunk/scripts/vserver.functions 2006-04-05 23:19:01.000000000 -0400 @@ -743,13 +743,13 @@ test -n "$_HAVE_CHBIND_OPTIONS" || _generateChbindOptions "$cfgdir" - test -z "$NAMESPACE_CLEANUP" || isAvoidNamespace "$cfgdir" || \ - $_VNAMESPACE --cleanup - _mountVserverInternal "$cfgdir"/fstab _mountVserverInternal "$cfgdir"/fstab.local _mountVserverInternal "$cfgdir"/fstab.remote $_CHBIND "${CHBIND_OPTS[@]}" + isNamespaceCleanup "$cfgdir" && \ + _namespaceCleanup + isAvoidNamespace "$cfgdir" || \ $_SECURE_MOUNT --rbind -n "$vdir" "/" } @@ -1099,3 +1099,29 @@ _saveSingleDiskLimit "$vdir" "$dlimit" done } + +function _namespaceCleanup +{ + local root=$(readlink -f "$vdir") + local tmp="$root" + local -a list + while [ "$tmp" ]; do + list=( "${list[@]}" "$tmp" ) + tmp="${tmp%/*}" + done + local -a list_umount + while read dev path opts; do + [ "$path" ] || continue + for i in "$root" /dev /proc; do + [ "${path#$i}" != "$path" ] && continue 2 + done + for i in "${list[@]}" /; do + [ "$path" = "$i" ] && continue 2 + done + list_umount=( "${list_umount[@]}" "$path" ) + done < /proc/mounts + for i in "${list_umount[@]}"; do + umount -l -n "$i" + done +} +