Don't mount the ns subsystem.
[util-vserver.git] / scripts / vserver.functions
index b394f50..b014abf 100644 (file)
@@ -41,6 +41,7 @@ declare -a ENTER_SHELL=()
 declare -a OPTS_VCONTEXT_CREATE=()
 declare -a OPTS_VCONTEXT_MIGRATE=()
 declare -a OPTS_VCONTEXT_ENTER=()
+OPT_VCONTEXT_CHROOT=--chroot
 declare -a OPTS_VATTRIBUTE=( --flag fakeinit )
 declare -a OPTS_VSCHED=()
 declare -a OPTS_ENV=()
@@ -146,6 +147,8 @@ function _generateIONiceCommand
     local ionice_class=2
     local ionice_priority=0
 
+    test -n "$_IONICE" || return 0
+
     test -r "$vdir/ionice/class" && read ionice_class <"$vdir"/ionice/class
     test -r "$vdir/ionice/priority" && read ionice_priority <"$vdir"/ionice/priority
 
@@ -405,6 +408,8 @@ function _generateFlagOptions
     isAvoidNamespace "$vdir" || {
        USE_VNAMESPACE=1
        CHCONTEXT_FLAG_OPTS=( "${CHCONTEXT_FLAG_OPTS[@]}" --flag namespace )
+       ! $_VSERVER_INFO - FEATURE PIVOT_ROOT || \
+           OPT_VCONTEXT_CHROOT=--pivot-root
     }
 }
 
@@ -913,6 +918,10 @@ function _mountVserverInternal
     # magic regarding the mtab file; when etc/mtab can not be touched,
     # add the '-n' flag to mount
     test -w etc -o -w etc/mtab || xflag=-n
+    if test -h etc/mtab; then
+       local l=$($_READLINK etc/mtab)
+       test "${l##/proc/}" = "$l" || xflag=-n
+    fi
     "$@" $_SECURE_MOUNT -a $xflag --chroot --fstab "$fstab" --rootfs no
     popd >/dev/null
 }
@@ -940,6 +949,8 @@ function mountVserver
     local ns_opt=$2
     local vdir=$1/vdir
     local mtab_src
+    local extra_opt=
+    local real_vdir
 
     test -e "$cfgdir"/fstab -o \
          -e "$cfgdir"/fstab.local -o \
@@ -960,8 +971,11 @@ function mountVserver
     isNamespaceCleanup "$cfgdir" && \
         _namespaceCleanup "$cfgdir"
 
+    real_vdir=$(getPhysicalDir "$vdir")
     isAvoidNamespace "$cfgdir" || \
-       $_SECURE_MOUNT --rbind -n -o dev "$vdir" "/"
+       $_SECURE_MOUNT --rbind -n -o dev "$vdir" "$real_vdir"
+    ! $_VSERVER_INFO - FEATURE PIVOT_ROOT || \
+       $_SECURE_MOUNT -n -o shared,rec "$real_vdir" "$real_vdir"
 }
 
 function _umountVserverInternal
@@ -1368,7 +1382,8 @@ function _namespaceCleanup
     while read -r dev path opts; do
        test -n "$path" || continue
        for i in "$root" /dev /proc; do
-           test "${path#$i}" != "$path" && continue 2
+           path_dir="${path}/"
+           test "${path_dir#${i}/}" != "${path_dir}" && continue 2
        done
        for i in "${list[@]}" /; do
            test "$path" = "$i" && continue 2
@@ -1428,6 +1443,10 @@ function _generateCgroupOptions
     findFile file "$__CONFDIR/.defaults/cgroup/subsys" ""
     if test -n "$file"; then
        read CGROUP_SUBSYS < "$file"
+    elif $_GREP -q '^ns[[:space:]]' /proc/cgroups; then
+       # Hack for the ns subsystem, with which we are incompatible
+       CGROUP_SUBSYS=$($_SED '/^#/d;/^ns[[:space:]]/d;s/[[:space:]].*//' /proc/cgroups | \
+                       (s=""; while read x; do test -n "$s" && s="$s,"; s="$s$x"; done; echo "$s"))
     fi
     findFile file "$__CONFDIR/.defaults/cgroup/inherit" ""
     if test -n "$file"; then
@@ -1477,7 +1496,10 @@ function _handleCgroup
 
            shopt -s nullglob
            for i in "$dir"/*; do
-               cat "$i" > "$CGROUP_MNT/$name/${i##*/}"
+               f="${i##*/}"
+               test "$f" != mnt -a "$f" != subsys -a \
+                   "$f" != inherit -a "$f" != name || continue
+               cat "$i" > "$CGROUP_MNT/$name/$f"
            done
        fi
        echo "$$" > "$CGROUP_MNT/$name/tasks"