Set vurpm variables
[util-vserver.git] / scripts / vserver.functions
index c40f95f..4cf8024 100644 (file)
@@ -154,15 +154,21 @@ function _generateNiceCommand
 function _generateIONiceCommand
 {
     local vdir=$1
-    local ionice_class=2
-    local ionice_priority=0
+    local ionice_class=
+    local ionice_priority=
 
     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
 
-    IONICE_CMD=( $_IONICE -c$ionice_class -n$ionice_priority )
+    test -n "$ionice_class$ionice_priority" || return 0
+
+    if test -z "$ionice_class" -a -n "$ionice_priority"; then
+       IONICE_CMD=( $_IONICE -c2 -n"$ionice_priority" )
+    else
+       IONICE_CMD=( $_IONICE ${ionice_class:+-c$ionice_class} ${ionice_priority:+-n$ionice_priority} )
+    fi
 }
 
 function _generatePersonalityOptions
@@ -206,6 +212,13 @@ function _generateBCapabilityOptions
     _readFileToArray "$vdir"/bcapabilities OPTS_VATTRIBUTE --bcap
 }
 
+function _generateUMaskOptions
+{
+    local vdir=$1
+
+    _readFileToArray "$vdir"/umask OPTS_VATTRIBUTE --umask
+}
+
 function _generateCapabilityOptions
 {
     local vdir=$1
@@ -442,6 +455,7 @@ function _generateChcontextOptions
 
     _generateCapabilityOptions "$vdir"
     _generateFlagOptions       "$vdir"
+    _generateUMaskOptions      "$vdir"
 
     CHCONTEXT_OPTS=( $SILENT_OPT \
                      "${CHCONTEXT_FLAG_OPTS[@]}" \
@@ -762,7 +776,11 @@ function disableInterfaces
            IP_ADDR_FLUSH)      ;;
            IP_LINK)            ;; ## Ignore the link-down command for now
            IP_ROUTE)           $_IP route del "$@";;
-           TUNCTL)             $_TUNCTL --~persist "$1";;
+           TUNCTL)
+               local dev="$1"
+               shift
+               $_TUNCTL --~persist "$@" "$dev"
+               ;;
            *)                  echo "Unknown interface-command type '$type'" >&2; false;;
        esac
     done
@@ -825,8 +843,11 @@ function prepareInit
     pushd "$1/vdir" >/dev/null
     case "$INITSTYLE" in
        sysv)
-           { $_FIND var/run  ! -type d -print0; \
-             $_FIND var/lock ! -type d -print0; } | xargs -0r $_CHROOT_SH rm
+           local -a dirs=( $($_CHROOT_SH realpath /var/run /var/lock | $_SED 's!^/*!!' || :) )
+           local dir
+           for dir in "${dirs[@]}"; do
+               $_FIND $dir ! -type d -print0 | xargs -0r $_CHROOT_SH rm
+           done
            ;;
        plain)
            $_CHROOT_SH rm .autofsck forcefsck 2>/dev/null || :
@@ -1484,8 +1505,19 @@ function _generateCgroupOptions
 function useCgroup
 {
     hasCgroup || return 1
-    test -e "$CGROUP_MNT/tasks" || return 1
-    memcg=""
+    if test -n "$CGROUP_MNT_PER_SS"; then
+       local existing=0
+       local ss
+       for ss in "${CGROUP_SUBSYS[@]}"; do
+           if test -e "$CGROUP_MNT/$ss/tasks"; then
+               let existing=${existing}+1
+           fi
+       done
+       test "$existing" -gt 0 || return 1
+    else
+       test -e "$CGROUP_MNT/tasks" || return 1
+    fi
+    local memcg=""
     if $_VSERVER_INFO - FEATURE memcg; then
        memcg=1
     fi
@@ -1518,13 +1550,14 @@ function _handleCgroup
 
     if test -n "$CGROUP_MNT_PER_SS"; then
        mnts=()
-       for ss in $($_SED '/^#/d;/^ns[[:space:]]/d;s/[[:space:]].*//' /proc/cgroups); do
+       for ss in "${CGROUP_SUBSYS[@]}"; do
            mnts=( "${mnts[@]}" "$CGROUP_MNT/$ss" )
        done
     else
        mnts=( "$CGROUP_MNT" )
     fi
     for mnt in "${mnts[@]}"; do
+       test -d "$mnt" || continue
        if test "$action" = "attach"; then
            if test -n "$CGROUP_BASE"; then
                local -a dirs=()
@@ -1556,8 +1589,13 @@ function _handleCgroup
                    for i in "$dir"/*; do
                        f="${i##*/}"
                        test "$f" != mnt -a "$f" != subsys -a \
-                           "$f" != inherit -a "$f" != name -a "$f" != base \
+                           "$f" != inherit -a "$f" != name -a "$f" != base -a \
+                           "$f" != per-ss \
                            || continue
+                       if test -n "$CGROUP_MNT_PER_SS"; then
+                           ss="${f%%.*}"
+                           test "$ss" = "${mnt##*/}" || continue
+                       fi
                        cat "$i" > "$mnt/$CGROUP_BASE$name/$f"
                    done
                fi