Remove vnamespace in favor of vspace and a small wrapper around it.
[util-vserver.git] / scripts / functions
index 8f73ec8..7b31944 100644 (file)
@@ -268,16 +268,39 @@ function unlock
     _VS_LOCKS="$@"
 }
 
-function _getVserverDir
+function get_init_cwd
+{
+    if test -n "$INIT_CWD"; then
+       echo "$INIT_CWD"
+    else
+       pwd
+    fi
+}
+function set_init_cwd
+{
+    INIT_CWD="`pwd`"
+    export INIT_CWD
+}
+
+function _setVserverDir
 {
     local vserver="$1"
     case "$vserver" in
-       ./*) VSERVER_DIR=`pwd`/$vserver     ;;
-       /*)  VSERVER_DIR=$vserver           ;;
-       *)   VSERVER_DIR=$__CONFDIR/$vserver;;
+       ./*) VSERVER_DIR="`get_init_cwd`/$vserver";;
+       /*)  VSERVER_DIR="$vserver"               ;;
+       *)   VSERVER_DIR="$__CONFDIR/$vserver"    ;;
     esac
 }
 
+function _setVserverName
+{
+    if test -e "$VSERVER_DIR"/name; then
+       read VSERVER_NAME <"$VSERVER_DIR"/name
+    else
+       VSERVER_NAME=$(basename "$VSERVER_DIR")
+    fi
+}
+
 function _pkgMountBindDir()
 {
     test "$1" != "$2" || return 0
@@ -496,6 +519,7 @@ function isNamespaceCleanup
 
     $_VSERVER_INFO - FEATURE namespace   || return 1
     cfgdir=$($_VSERVER_INFO "$1" CFGDIR) || return 1
+    isAvoidNamespace "$1"                && return 1
     test -e "$cfgdir"/namespace-cleanup  && return 0
     test -e "$cfgdir"/nonamespace-cleanup -o \
          -e "$__CONFDIR"/.defaults/nonamespace-cleanup && return 1
@@ -557,7 +581,7 @@ function _getProcNumberCount
 
     # Use /proc/virtual from kernel 2.6 when possible
     if test -d "/proc/virtual"; then
-       set -- $($_GREP '^PROC:' "/proc/virtual/$1/limit" 2>/dev/null)
+       set -- $($_GREP '^Tasks:' "/proc/virtual/$1/status" 2>/dev/null)
        _gp_procnr_cnt=$2
     else
        _gp_procnr_cnt=$($_VPS ax | $_AWK '{print $2}' | $_GREP -x "$1" | $_WC -l )
@@ -577,10 +601,16 @@ function getVserverStatus
     read _gvs_ctx <"$1"/run
     eval "$2"=\$_gvs_ctx
 
-    test -n "$3"     || return 0
-    local _gvs_tmp
-    _getProcNumberCount "$_gvs_ctx" _gvs_tmp
-    eval "$3"=\$_gvs_tmp
+    if test "$1" = "$($_VUNAME -g --xid "$_gvs_ctx" context)"; then
+       test -n "$3" || return 0
+       local _gvs_tmp
+       _getProcNumberCount "$_gvs_ctx" _gvs_tmp
+       eval "$3"=\$_gvs_tmp
+    else
+       test -n "$3" || return 1
+       eval "$3"=0
+       _gvs_tmp=0
+    fi
 
     if test "$_gvs_tmp" = 0; then
        local runfile=$($_READLINK "$1/run")
@@ -622,13 +652,17 @@ function getFileValue
     eval read "$_gfv_var" <"$_gfv_file"
 }
 
-## Called as 'getFileArray <varname> <filename>'
+## Called as 'getFileArray <varname> <filename>+'
 function getFileArray
 {
-    test -r "$2" || return 1
-    
+    local _gfa_var=$1
+    local _gfa_file
+    shift
+
+    findFile _gfa_file "$@" ''
+    test -n "$_gfa_file" -a -r "$_gfa_file" || return 0
     local IFS=$_VS_NEWLINE
-    eval "$1"='( $(< "$2") )'
+    eval "$_gfa_var"='( $(< "$_gfa_file") )'
 }
 
 function checkComponents
@@ -695,8 +729,12 @@ function setDefaultTTY
        "$__CONFDIR/.defaults/apps/init/tty" \
        $2 /dev/null
 
-    exec   <$ttyname
-    exec  &>$ttyname
+    if test -f "$ttyname"; then
+       exec </dev/null
+    else
+       exec <$ttyname
+    fi
+    exec    >>$ttyname 2>&1
 }
 
 ## Usage: killContext <XID> [<SIG>]
@@ -826,9 +864,11 @@ function vshelper.doSanityCheck
        vshelper=$(cat "$proc_file")
 
        $_CMP -s "$vshelper" "$_VSHELPER" || {
+           local readable=""
+           test -r "$vshelper" && readable=1
            warnings=( "${warnings[@]}"
                       $"The configured vshelper '$vshelper' does not match the 'vshelper'
-  script of the util-vserver package"
+  script of the util-vserver package.${readable:+ Maybe you have two versions installed?}"
                     )
            solution_disable=1
            solution_sysctl=1
@@ -960,7 +1000,11 @@ function vshelper.doInit
     
     local xid
     xid=$($_VSERVER_INFO "$1" CONTEXT false) && test -n "$xid" || {
-       warning $"vshelper.init: can not determine xid of vserver '$vserver'; returned value was '$xid'"
+       warning $"vshelper.init: can not determine xid of vserver '$vserver'; returned value was '$xid'
+
+This usually means that you're using an init-less init-style, but the
+guest isn't configured to start any service. Try enabling a service,
+changing the init-style, or making the contexts persistent."
        return 1
     }
 
@@ -1044,6 +1088,12 @@ function vshelper.doStopSync
        test ! -p "$VSHELPER_STOP_SYNC" || echo stopped > "$VSHELPER_STOP_SYNC"
 }
 
+function vshelper.isStopSync
+{
+       test -p "$VSHELPER_STOP_SYNC" || return 1
+       return 0
+}
+
 function _rpmFake.getCapFlags
 {
     local ctx=$1