summaryrefslogtreecommitdiff
blob: d5b7550f9f19e832247f53ba14b404b94d8f5e75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#! /bin/sh /usr/share/dpatch/dpatch-run
## 12_vnamespace_cleanup.dpatch by Micah Anderson <Micah Anderson <micah@debian.org>>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: No description.

@DPATCH@
Index: util-vserver-0.30.210/doc/configuration.xml
===================================================================
--- util-vserver-0.30.210.orig/doc/configuration.xml
+++ util-vserver-0.30.210/doc/configuration.xml
@@ -37,6 +37,14 @@ the 'barrier' attribute. Else, common ch
       </description>
     </boolean>
 
+    <boolean id="global-namespace-cleanup" name="namespace-cleanup">
+      <description>
+Enable namespace cleanup globally. It can be overridden for a single vserver
+by setting the <optionref ref="global-nonamespace-cleanup">nonamespace-cleanup</optionref> flag
+there.
+      </description>
+    </boolean>
+
     <link name="run.rev">
       <description>
 Path of the vserver run reverse directory. This directory contains
@@ -344,6 +352,19 @@ the 'barrier' attribute. Else, common ch
       </description>
     </boolean>
 
+    <boolean id="global-nonamespace-cleanup" name="nonamespace-cleanup">
+      <description>
+Overrides the global <optionref ref="global-namespace-cleanup">namespace-cleanup</optionref> flag and disables
+namespace cleanup for the current vserver.
+      </description>
+    </boolean>
+
+    <boolean name="namespace-cleanup">
+      <description>
+Enable namespace cleanup for the current vserver.
+      </description>
+    </boolean>
+
     <hash name="schedule">
       <description>
 [experimental; name is subject of possible change] Contains the
Index: util-vserver-0.30.210/scripts/functions
===================================================================
--- util-vserver-0.30.210.orig/scripts/functions
+++ util-vserver-0.30.210/scripts/functions
@@ -480,6 +480,18 @@ function isAvoidNamespace
          -e "$cfgdir"/nonamespace
 }
 
+function isNamespaceCleanup
+{
+    local cfgdir
+
+    $_VSERVER_INFO - FEATURE namespace   || return 0
+    cfgdir=$($_VSERVER_INFO "$1" CFGDIR) || return 0
+    test -e "$cfgdir"/nonamespace-cleanup && return 0
+    test -e "$__CONFDIR"/.defaults/namespace-cleanup -o \
+         -e "$cfgdir"/namespace-cleanup && return 1
+    return 0
+}
+
 ## Usage: getAllVservers <var> [<KIND>*]
 function getAllVservers
 {
Index: util-vserver-0.30.210/scripts/vserver.functions
===================================================================
--- util-vserver-0.30.210.orig/scripts/vserver.functions
+++ util-vserver-0.30.210/scripts/vserver.functions
@@ -792,13 +792,13 @@ function mountVserver
 
     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" "/"
 }
@@ -1150,3 +1150,29 @@ function saveDiskLimits
 	_saveSingleDiskLimit "$vdir" "$dlimit"
     done
 }
+
+function _namespaceCleanup
+{
+    local root=$(readlink -f "$vdir")
+    local tmp="$root"
+    local list=""
+    while [ "$tmp" ]; do
+	list="$list $tmp"
+	tmp="${tmp%/*}"
+    done
+    local 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="$path $list_umount"
+    done < /proc/mounts
+    for i in $list_umount; do
+        umount $i
+    done
+}
+