_VS_NEWLINE='
'
declare -r _VS_NEWLINE=${_VS_NEWLINE:0-1}
-declare -r VS_ALLVSERVERS_ARGS=all,marked,unmarked,stopped,running
function findObject
{
_VS_LOCKS="$@"
}
+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="`get_init_cwd`/$vserver";;
+ /*) VSERVER_DIR="$vserver" ;;
+ *) VSERVER_DIR="$__CONFDIR/$vserver" ;;
+ esac
+}
+
+function _setVserverName
+{
+ VSERVER_NAME=$(basename "$VSERVER_DIR")
+}
+
function _pkgMountBindDir()
{
test "$1" != "$2" || return 0
$_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
+ isAvoidNamespace "$1" && return 1
+ test -e "$cfgdir"/namespace-cleanup && return 0
+ test -e "$cfgdir"/nonamespace-cleanup -o \
+ -e "$__CONFDIR"/.defaults/nonamespace-cleanup && return 1
+ return 0
}
## Usage: getAllVservers <var> [<KIND>*]
{
local _ga_i
declare -a _ga_tmp=()
+ local _ga_IFS="$IFS"
+ IFS=,
+ local -a _ga_marks=( $3 )
+ IFS="$_ga_IFS"
for _ga_i in $__CONFDIR/*; do
isRegularFile "$_ga_i" -d || continue
(STOPPED) ! $_VSERVER "$_ga_i" running &>/dev/null || _ga_doadd=;;
(RUNNING) $_VSERVER "$_ga_i" running &>/dev/null || _ga_doadd=;;
(ALL) ;;
+ (MARK) local _ga_j
+ local _ga_mark
+ local _ga_f=false
+ local _ga_invert=false
+ for _ga_j in "${_ga_marks[@]}"; do
+ _ga_mark="$(echo "$_ga_j" | $_SED 's/^[!~]//')"
+ test "$_ga_j" = "$_ga_mark" || _ga_invert=true
+ test -s "$_ga_markfile" && $_GREP -qx "$_ga_mark" "$_ga_markfile" && \
+ _ga_f=true || :
+ done
+ test $_ga_f = $_ga_invert && \
+ _ga_doadd=
+ ;;
(*) panic $"Unknown vserver tagging '$2'";;
esac
eval $1='( "${_ga_tmp[@]}" )'
}
+declare -r VS_ALLVSERVERS_ARGS=all,marked,unmarked,stopped,running,mark:
## Usage: getAllVserversByArg <var> <arg>
function getAllVserversByArg
{
local _gav_mark=
-
- case $2 in
- (--all) _gav_mark=ALL;;
- (--marked) _gav_mark=MARKED;;
- (--unmarked) _gav_mark=UNMARKED;;
- (--stopped) _gav_mark=STOPPED;;
- (--running) _gav_mark=RUNNING;;
- (*) return 1;;
- esac
+ local _gav_v="$1"
+ local _gav_first=1
+ local _gav_res=()
+ shift
+
+ while test "$#" -ge 1; do
+ local _gav_extra=
+ local _gav_tmp=()
+
+ case "$1" in
+ (--all) _gav_mark=ALL;;
+ (--marked) _gav_mark=MARKED;;
+ (--unmarked) _gav_mark=UNMARKED;;
+ (--stopped) _gav_mark=STOPPED;;
+ (--running) _gav_mark=RUNNING;;
+ (--mark*) _gav_mark=MARK
+ _gav_extra=${_gav_i##*=}
+ test -n "$_gav_extra" -a "$_gav_extra" != "--mark" || \
+ _gav_extra="$2"
+ shift
+ ;;
+ (--) break;;
+ (*) set -- "$_gav_v" "$@"
+ return 1;;
+ esac
- getAllVservers "$1" "$_gav_mark"
+ getAllVservers _gav_tmp "$_gav_mark" $_gav_extra
+ if test -n "$_gav_first"; then
+ _gav_res=( "${_gav_tmp[@]}" )
+ else
+ local _gav_i=0
+ local _gav_n="${#_gav_res[@]}"
+ while test $_gav_i -lt $_gav_n; do
+ local _gav_found=0
+ for _gav_j in "${_gav_tmp[@]}"; do
+ if test "$_gav_j" = "${_gav_res[$_gav_i]}"; then
+ _gav_found=1
+ break
+ fi
+ done
+ if test "$_gav_found" = 0; then
+ unset _gav_res[$_gav_i]
+ fi
+ let ++_gav_i
+ done
+ _gav_res=( "${_gav_res[@]}" )
+ fi
+ shift
+ _gav_first=
+ done
+ eval $_gav_v='( "${_gav_res[@]}" )'
}
## Usage: _getProcNumberCount <ctx> <var>
# 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 )
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")
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
"$__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>]
#$_VKILL -s CONT --xid "$1" 1 &>/dev/null || :
}
+function useVlogin
+{
+ test ! -e "$__CONFDIR/.defaults/apps/vlogin/disable"
+}
+
## Usage: pkgmgmt.guessStyle <vserver> <resultvar>
function pkgmgmt.guessStyle()
{
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
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
}
eval $2=\$_vgst_tmp
}
+function vshelper.initStopSync
+{
+ local _iss_sync_dir=$($_MKTEMPDIR vshelper-stop-sync.XXXXXX) || {
+ warning $"Failed to generate directory for vshelper sync"
+ exit 1
+ }
+ $_MKFIFO -m700 "$_iss_sync_dir/pipe"
+
+ eval "$1"=\$_iss_sync_dir
+ VSHELPER_STOP_SYNC="$_iss_sync_dir/pipe"
+ export VSHELPER_STOP_SYNC
+}
+
+function vshelper.waitForStopSync
+{
+ local sync_dir=$1
+ cat "$sync_dir/pipe" &> /dev/null
+ rm -fr "$sync_dir"
+}
+
+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
{