use $(LIBENSCVECTOR) instead of libensc_vector.a
[util-vserver.git] / util-vserver / scripts / functions
index 66c3bd3..e9123f8 100644 (file)
@@ -24,23 +24,23 @@ declare -r _VS_NEWLINE=${_VS_NEWLINE:0-1}
 
 function findObject
 {
-    local mod=$1
-    local var=$2
-    local file=
-    local i=X
+    local _fo_mod=$1
+    local _fo_var=$2
+    local _fo_file=
+    local _fo_i=X
     shift 2
     
-    for i; do
-       test "$i"        || continue
-       test ! $mod "$i" || { file=$i; break; }
+    for _fo_i; do
+       test -n "$_fo_i"         || continue
+       test ! $_fo_mod "$_fo_i" || { _fo_file=$_fo_i; break; }
     done
 
-    test -z "$i" -o "$file" || {
-       echo "Can not find file for '$var'; aborting"
+    test -z "$_fo_i" -o -n "$_fo_file" || {
+       echo "Can not find file for '$_fo_var'; aborting"
        exit 1
     } >&2
 
-    eval "$var=\"$file\""
+    eval "$_fo_var=\"$_fo_file\""
 }
 
 function findFile
@@ -62,8 +62,8 @@ function findAndCopy
     shift
     findFile tmp "$@"
 
-    test "$tmp" -a -s "$tmp" || return 0
-    cp -af "$tmp" "$dst"
+    test -n "$tmp" -a -s "$tmp" || return 0
+    $_CP -af "$tmp" "$dst"
 }
 
 function getPhysicalDir
@@ -74,7 +74,7 @@ function getPhysicalDir
 ## Usage: logging <message>
 function logging
 {
-    if test "$_VS_LOGFILE"; then
+    if test -n "$_VS_LOGFILE"; then
        echo "$@" >>"$_VS_LOGFILE"
     else
        echo "$@"
@@ -84,7 +84,7 @@ function logging
 ## Usage: warning <message>
 function warning
 {
-    if test "$_VS_ERRFILE"; then
+    if test -n "$_VS_ERRFILE"; then
        echo "$@" >>"$_VS_ERRFILE"
     else
        echo "$@" >&2
@@ -94,7 +94,7 @@ function warning
 ## Usage: panic <message>
 function panic
 {
-    if test "$_VS_ERRFILE"; then
+    if test -n "$_VS_ERRFILE"; then
        echo "$@" >>"$_VS_ERRFILE"
     else
        echo "$@" >&2
@@ -115,7 +115,7 @@ function execute
 function isNumber
 {
     local tmp
-    let tmp=$1+0 2>/dev/null || test -z "${1//0/}" -a "$1" || return 1
+    let tmp=$1+0 2>/dev/null || test -z "${1//0/}" -a -n "$1" || return 1
     return 0
 }
 
@@ -125,13 +125,13 @@ function colorize
     local      style=$1
     shift
     
-    if ! tty -s; then
+    if ! $_TTY -s; then
        "$@"
     else
        local   cfile
-       findFile cfile "$CONFDIR"/.defaults/styles/"$style" ''
-       if test "$cfile"; then
-         cat "$cfile"
+       findFile cfile "$__CONFDIR"/.defaults/styles/"$style" ''
+       if test -n "$cfile"; then
+         $_CAT "$cfile"
        else
          case "$style" in
            (bold)      echo -ne "\e[1m";;
@@ -151,7 +151,7 @@ function colorize
 ## Usage: xtermTitle <title>
 function xtermTitle
 {
-    tty -s || return 0
+    $_TTY -s || return 0
     echo -ne "\e]0;$@\007"
 }
 
@@ -159,12 +159,12 @@ _VS_LOCKS=''
 ## Usage: lock <lockfile> [<timeout>]
 function lock
 {
-    local tmp=$(mktemp /tmp/vserver-lock.XXXXXX)
-    rm -f $tmp
-    mkfifo -m600 $tmp
+    local tmp=$($_MKTEMP /tmp/vserver-lock.XXXXXX)
+    $_RM -f $tmp
+    $_MKFIFO -m600 $tmp
 
     $_LOCKFILE "$1" $tmp $2 &
-    grep -q true $tmp 2>/dev/null || return 1
+    $_GREP -q true $tmp 2>/dev/null || return 1
     
     _VS_LOCKS="$! $_VS_LOCKS"
 }
@@ -189,7 +189,7 @@ function _pkgMountBindDir()
 {
     test "$1" != "$2" || return 0
 
-    mount -n --bind "$1" "$2"
+    $_MOUNT -n --bind "$1" "$2"
 }
 
 function _pkgSetVarsBase
@@ -212,14 +212,14 @@ function _pkgSetVarsBase
            fi
            ;;
         *)
-           BASEDIR=$CONFDIR/$vserver
+           BASEDIR=$__CONFDIR/$vserver
            test -d "$BASEDIR" || {
                echo "Can not find configuration-directory"
                exit 1
            } >&2
            
            VDIR=$BASEDIR/vdir
-           test -d "$VDIR"   || VDIR=$DEFAULT_VSERVERDIR/$vserver
+           test -d "$VDIR"   || VDIR=$__DEFAULT_VSERVERDIR/$vserver
            VDIR=$(getPhysicalDir "$VDIR")
            
            PKGDIR=$BASEDIR/apps/pkgmgmt
@@ -242,7 +242,7 @@ function _pkgSetVarsBase
 
 function _pkgSetVarsRPM
 {
-    if test "$PKGDIR"; then
+    if test -n "$PKGDIR"; then
        findDir RPMETCDIR    $PKGDIR/rpmetc      $PKGDIR/base/rpm/etc       /etc/rpm
        findDir RPMSTATEDIR  $PKGDIR/rpmstate    $PKGDIR/base/rpm/state
 
@@ -260,7 +260,7 @@ function _pkgSetVarsRPM
 
 function _pkgSetVarsApt
 {
-    if test "$PKGDIR"; then
+    if test -n "$PKGDIR"; then
        findDir APTETCDIR    $PKGDIR/aptetc      $PKGDIR/base/apt/etc       /etc/apt
        findDir APTSTATEDIR  $PKGDIR/aptstate    $PKGDIR/base/apt/state
        findDir APTCACHEDIR  $PKGDIR/aptcache    $PKGDIR/base/apt/cache
@@ -276,6 +276,18 @@ function _pkgSetVarsApt
     test -z "$APT_CONFIG" || export APT_CONFIG
 }
 
+function _pkgSetVarsYum
+{
+    if test -n "$PKGDIR"; then
+       findDir YUMETCDIR    $PKGDIR/yumetc      $PKGDIR/base/yum/etc       /etc
+       findDir YUMCACHEDIR  $PKGDIR/yumcache    $PKGDIR/base/yum/cache
+    else
+       findDir YUMETCDIR    "$VDIR"/etc         /etc
+       findDir YUMCACHEDIR  "$VDIR"/var/cache/yum
+    fi
+}
+
+
 function _pkgMountBase
 {
     :
@@ -286,6 +298,11 @@ function _pkgMountApt
     :
 }
 
+function _pkgMountYum
+{
+    :
+}
+
 function _pkgMountRPM
 {
     _pkgMountBindDir "$RPMETCDIR" /etc/rpm
@@ -293,18 +310,18 @@ function _pkgMountRPM
 
     pushd "$VDIR" >/dev/null
 
-    "$_SECURE_MOUNT" --chroot -n --bind "$RPMSTATEDIR" "$_rpmdb_mntpoint"
+    $_SECURE_MOUNT --chroot -n --bind "$RPMSTATEDIR" "$_rpmdb_mntpoint"
     test -z "$WORKAROUND_106057" || mount -n --bind "$RPMSTATEDIR" "$_rpmdb_mntpoint"
 
     test -e "$VDIR"/proc/self/status || \
-       "$_SECURE_MOUNT" --chroot -n -t proc none /proc
+       $_SECURE_MOUNT --chroot -n -t proc none /proc
 
     popd >/dev/null
 }
 
 function _pkgSetEnvBase
 {
-    test "$EXECDIR"   = "/" || {
+    test "$EXECDIR" = "/" || {
        PATH=$EXECDIR:$PATH
        LD_LIBRARY_PATH=$EXECDIR${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
     }
@@ -317,6 +334,11 @@ function _pkgSetEnvApt
     :
 }
 
+function _pkgSetEnvYum
+{
+    :
+}
+
 function _pkgSetEnvRPM
 {
     CUR_VSERVER=$vserver
@@ -337,6 +359,7 @@ function pkgInit
        case "$i" in
            rpm)        _pkgSetVarsRPM;;
            apt)        _pkgSetVarsApt;;
+           yum)        _pkgSetVarsYum;;
            *)          echo "Unknown packaging flavor" >&2; exit 1;;
        esac
     done
@@ -346,6 +369,7 @@ function pkgInit
        case "$i" in
            rpm)        _pkgMountRPM;;
            apt)        _pkgMountApt;;
+           yum)        _pkgMountYum;;
        esac
     done
 
@@ -354,6 +378,7 @@ function pkgInit
        case "$i" in
            rpm)        _pkgSetEnvRPM;;
            apt)        _pkgSetEnvApt;;
+           yum)        _pkgSetEnvYum;;
        esac
     done
 
@@ -368,45 +393,45 @@ function isAvoidNamespace
     $_VSERVER_INFO - FEATURE namespace   || return 0
     cfgdir=$($_VSERVER_INFO "$1" CFGDIR) || return 0
     test ! -e "$cfgdir"/namespace        || return 1
-    test -e "$CONFDIR"/.defaults/nonamespace -o \
+    test -e "$__CONFDIR"/.defaults/nonamespace -o \
          -e "$cfgdir"/nonamespace
 }
 
 function getAllVservers
 {
-    local i
-    declare -a _tmp=()
+    local _ga_i
+    declare -a _ga_tmp=()
 
-    for i in $CONFDIR/*; do
-       test   -d "$i"          || continue
-       test ! -e "$i"/disabled || continue
-       test   -d "$i"/vdir     || continue
-       case "$i" in
+    for _ga_i in $__CONFDIR/*; do
+       test   -d "$_ga_i"          || continue
+       test ! -e "$_ga_i"/disabled || continue
+       test   -d "$_ga_i"/vdir     || continue
+       case "$_ga_i" in
            *.~*~) continue;;
        esac
 
-       _tmp=( "${_tmp[@]}" "${i##$CONFDIR/}")
+       _ga_tmp=( "${_ga_tmp[@]}" "${_ga_i##$__CONFDIR/}")
     done
 
-    eval $1='( "${_tmp[@]}" )'
+    eval $1='( "${_ga_tmp[@]}" )'
 }
 
 ## Usage: _getProcNumberCount <ctx> <var>
 function _getProcNumberCount
 {
-    local var=$2
-    local procnr_cnt=0
+    local _gp_var=$2
+    local _gp_procnr_cnt=0
 
     # 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)
-       procnr_cnt=$2
+       _gp_procnr_cnt=$2
     else
-       procnr_cnt=$($_VPS ax | $_AWK '{print $2}' | $_GREP -x "$_ctx" | $_WC -l )
+       _gp_procnr_cnt=$($_VPS ax | $_AWK '{print $2}' | $_GREP -x "$1" | $_WC -l )
     fi
 
-    let procnr_cnt=procnr_cnt+0
-    eval $var=\$procnr_cnt
+    let _gp_procnr_cnt=_gp_procnr_cnt+0
+    eval $_gp_var=\$_gp_procnr_cnt
 }
 
 ## Usage: getVserverCtx <vdir> <result-varname> [<procnumber-varname> [<do-cleanup>]]
@@ -415,18 +440,18 @@ function getVserverStatus
 {
     test -r "$1"/run || return 1
 
-    local _ctx
-    read _ctx <"$1"/run
-    eval "$2"=\$_ctx
+    local _gvs_ctx
+    read _gvs_ctx <"$1"/run
+    eval "$2"=\$_gvs_ctx
 
-    test "$3"        || return 0
-    local _tmp
-    _getProcNumberCount "$_ctx" _tmp
-    eval "$3"=\$_tmp
+    test -n "$3"     || return 0
+    local _gvs_tmp
+    _getProcNumberCount "$_gvs_ctx" _gvs_tmp
+    eval "$3"=\$_gvs_tmp
 
-    if test "$_tmp" = 0; then
+    if test "$_gvs_tmp" = 0; then
        local runfile=$($_READLINK "$1/run")
-       test -z "$4" || rm -f "$runfile"
+       test -z "$4" || $_RM -f "$runfile"
        return 1
     fi
 
@@ -444,19 +469,24 @@ function isCtxRunning
 ## Usage: isVserverRunning <vdir> [<ctx-varname>]
 function isVserverRunning
 {
-    local ctx procnum
+    local _ivr_ctx _ivr_procnum
 
-    getVserverStatus "$1" ctx procnum 1 || return 1
-    test $procnum != 0                  || return 1
-    test -z "$2" || eval "$2"=\$ctx
+    getVserverStatus "$1" _ivr_ctx _ivr_procnum 1 || return 1
+    test "$_ivr_procnum" != 0                     || return 1
+    test -z "$2" || eval "$2"=\$_ivr_ctx
     return 0
 }
 
-## Called as 'getFileValue <varname> <filename>'
+## Called as 'getFileValue <varname> <filename>+'
 function getFileValue
 {
-    test -r "$2" || return 0
-    eval read "$1" <"$2"
+    local _gfv_var=$1
+    local _gfv_file
+    shift
+
+    findFile _gfv_file "$@" ''
+    test -n "$_gfv_file" -a -r "$_gfv_file" || return 0
+    eval read "$_gfv_var" <"$_gfv_file"
 }
 
 ## Called as 'getFileArray <varname> <filename>'
@@ -479,11 +509,11 @@ function checkComponents
     for i; do
        local failed=
        case "$i" in
-           core)       test -x "$_CHBIND"           || failed=1;;
-           build)      test -x "$_VSERVER_BUILD"    || failed=1;;
-           sysv)       test -x "$INITRDDIR/vserver" || failed=1;;
-           devel)      test -d "$INCLUDEDIR/vserver.h" || failed=1;;
-           *)          echo "Unknown component '$i'" >&2
+           (core)      test -x "$_CHBIND"           || failed=1;;
+           (build)     test -x "$_VSERVER_BUILD"    || failed=1;;
+           (sysv)      test -x "$__INITRDDIR/vserver"    || failed=1;;
+           (devel)     test -d "$__INCLUDEDIR/vserver.h" || failed=1;;
+           (*)         echo "Unknown component '$i'" >&2
                        return false
                        ;;
        esac
@@ -500,7 +530,8 @@ function checkComponents
 ## Usage: isKernelAPI <ver> [<cmp-modifier>]
 function isKernelAPI
 {
-    local api=$($_VSERVER_INFO - APIVER) || api=0
+    local api
+    api=$($_VSERVER_INFO - APIVER) || api=0
     test $[ $api ] -${2:-ge} $[ $1 ]
 }
 
@@ -513,7 +544,7 @@ function callInNamespace
     ctx=$( $_VSERVER_INFO "$1" CONTEXT f ) || ctx=
 
     shift
-    if test "$ctx"; then
+    if test -n "$ctx"; then
        $_VNAMESPACE --enter "$ctx" -- "$@"
     else
        "$@"
@@ -528,7 +559,7 @@ function setDefaultTTY
     cfgdir=$($_VSERVER_INFO "$1" APPDIR init) || cfgdir=
     findObject -e ttyname \
        ${cfgdir:+"$cfgdir"/tty} \
-       "$CONFDIR/.defaults/apps/init/tty" \
+       "$__CONFDIR/.defaults/apps/init/tty" \
        $2 /dev/null
 
     exec   <$ttyname
@@ -538,21 +569,22 @@ function setDefaultTTY
 ## Usage: pkgmgmt.guessStyle <vserver> <resultvar>
 function pkgmgmt.guessStyle()
 {
-    local vdir=$($_VSERVER_INFO "$1" VDIR) || {
+    local _pgs_vdir
+    _pgs_vdir=$($_VSERVER_INFO "$1" VDIR) || {
        echo $"Can not determine vserver-root" >&2
        return 1
     }
-    local cfgdir=$($_VSERVER_INFO "$1" APPDIR pkgmgmt) || :
+    local _pgs_cfgdir=$($_VSERVER_INFO "$1" APPDIR pkgmgmt) || :
 
-    if test "$cfgdir" -a -e "$cfgdir"/style; then
-       read style <"$cfgdir"/style
-    elif test -e "$vdir"/etc/redhat-release -o -e "$vdir"/etc/fedora-release; then
+    if test -n "$_pgs_cfgdir" -a -e "$_pgs_cfgdir"/style; then
+       read style <"$_pgs_cfgdir"/style
+    elif test -e "$_pgs_vdir"/etc/redhat-release -o -e "$_pgs_vdir"/etc/fedora-release; then
        style=redhat
-    elif test -e "$vdir"/etc/mandrake-release; then
+    elif test -e "$_pgs_vdir"/etc/mandrake-release; then
        style=mandrake
-    elif test -e "$vdir"/etc/debian_version; then
+    elif test -e "$_pgs_vdir"/etc/debian_version; then
        style=debian
-    elif test -e "$vdir"/etc/SuSE-release; then
+    elif test -e "$_pgs_vdir"/etc/SuSE-release; then
        style=suse
     else
        echo $"Can not determine packagemanagement style" >&2
@@ -583,7 +615,7 @@ function pkgmgmt.isAptAvailable
     local is_internal="$3"
     
     local have_apt i
-    if test "$is_internal"; then
+    if test -n "$is_internal"; then
        have_apt=1
        test -d "$cfgdir"/base/apt -o -d "$cfgdir"/aptetc || have_apt=
     else
@@ -593,9 +625,31 @@ function pkgmgmt.isAptAvailable
        done
     fi
 
-    test "$have_apt" && return 0 || return 1
+    test -n "$have_apt" && return 0 || return 1
+}
+
+## Usage: pkgmgmt.isYumAvailable <cfgdir> <vdir> [<is-internal>]
+function pkgmgmt.isYumAvailable
+{
+    local cfgdir="$1"
+    local vdir="$2"
+    local is_internal="$3"
+    
+    local have_yum i
+    if test -n "$is_internal"; then
+       have_yum=1
+       test -d "$cfgdir"/base/yum -o -d "$cfgdir"/yumetc || have_yum=
+    else
+       have_yum=
+       for i in /bin /usr/bin /usr/local/bin; do
+           test ! -x "$vdir$i"/yum || { have_yum=1; break; }
+       done
+    fi
+
+    test -n "$have_yum" && return 0 || return 1
 }
 
+
 function vshelper.doSanityCheck
 {
     local vshelper this_xid i
@@ -616,12 +670,12 @@ function vshelper.doSanityCheck
     if ! test -r "$proc_file"; then
        vshelper=
        warnings=( "${warnings[@]}"
-                  $"File '$proc_file' does not exists but is required for vshelper setup" )
+                  $"File '$proc_file' does not exist but is required for vshelper setup" )
         solution_disable=1
     else
        vshelper=$(cat "$proc_file")
 
-       cmp -s "$vshelper" "$_VSHELPER" || {
+       $_CMP -s "$vshelper" "$_VSHELPER" || {
            warnings=( "${warnings[@]}"
                       $"The configured vshelper '$vshelper' does not match the 'vshelper'
   script of the util-vserver package"
@@ -631,10 +685,10 @@ function vshelper.doSanityCheck
        }
     fi
 
-    test -d "$VSHELPERSTATEDIR" || {
+    test -d "$__VSHELPERSTATEDIR" || {
        warnings=( "${warnings[@]}"
                   $"\
-The vshelper state-directory '$VSHELPERSTATEDIR' does not exist; since
+The vshelper state-directory '$__VSHELPERSTATEDIR' does not exist; since
 it is created by 'make install', this indicates a serious problem with
 your util-vserver installation" )
        solution_disable=1
@@ -655,9 +709,9 @@ To fix this, you can:"
 
        test -z "$solution_disable" || warning $"\
 * disable vshelper entirely by executing
-  | touch \"$CONFDIR/.defaults/apps/vshelper/disabled\"
+  | touch \"$__CONFDIR/.defaults/apps/vshelper/disabled\"
 * disable only this message by executing
-  | touch \"$CONFDIR/.defaults/apps/vshelper/warning-disabled\""
+  | touch \"$__CONFDIR/.defaults/apps/vshelper/warning-disabled\""
 
        test -x "$solution_sysctl" || warning $"\
 * configure the util-vserver vshelper script, e.g. by adding
@@ -677,38 +731,53 @@ To fix this, you can:"
 function vshelper.isEnabled
 {
     local f=${1:+$1-}disabled
-    test ! -e "$CONFDIR"/.defaults/apps/vshelper/"$f"       || return 1
+    test ! -e "$__CONFDIR"/.defaults/apps/vshelper/"$f"       || return 1
     $_VSERVER_INFO - FEATURE vshelper                       || return 1
-    if test "$2"; then
-       local appdir=$($_VSERVER_INFO "$2" APPDIR vshelper) || return 0
+    if test -n "$2"; then
+       local appdir
+       appdir=$($_VSERVER_INFO "$2" APPDIR vshelper)       || return 0
        test -z "$2" -o ! -e "$appdir/$f"                   || return 1
     fi
 
     return 0
 }
 
+## Usage: vshelper.isDebug [<vserver>]
+function vshelper.isDebug
+{
+    test ! -e "$__CONFDIR"/.defaults/apps/vshelper/debug           || return 1
+    $_VSERVER_INFO - FEATURE vshelper                       || return 1
+    if test -n "$1"; then
+       local appdir
+       appdir=$($_VSERVER_INFO "$1" APPDIR vshelper)       || return 1
+       test -z "$1" -o ! -e "$appdir/debug"                || return 1
+    fi
+
+    return 0
+}
+
 function vshelper._getHandlerInternal
 {
-    local var=$1
-    local tmp
+    local _vghi_var=$1
+    local _vghi_tmp
     shift
     shift      ## HACK: see below the note about the 'set -u' mode
     
     while test "$#" -ge 2; do
-       local mod=$1
-       local obj=$2
+       local _vghi_mod=$1
+       local _vghi_obj=$2
        shift 2
 
-       test "$mod" "$obj" || continue
-       case "$mod" in
+       test "$_vghi_mod" "$_vghi_obj" || continue
+       case "$_vghi_mod" in
            (-x)
-               eval $var=\$obj
+               eval $_vghi_var=\$_vghi_obj
                ;;
            (-e)
-               read tmp <"$obj"
-               eval $var=:\$tmp
+               read _vghi_tmp <"$_vghi_obj"
+               eval $_vghi_var=:\$_vghi_tmp
                ;;
-           (*) panic $"Internal error, unexpected modifier '$mod'"
+           (*) panic $"Internal error, unexpected modifier '$_vghi_mod'"
        esac
        return 0
     done
@@ -719,17 +788,18 @@ function vshelper._getHandlerInternal
 ## Usage: vshelper.getHandler <result-var> <vserver> <action>
 function vshelper.getHandler
 {
-    local appdir=$($_VSERVER_INFO "$2" APPDIR vshelper) || appdir=
-    local script
-    declare -a search_list=( X )
+    local _vgh_appdir
+    _vgh_appdir=$($_VSERVER_INFO "$2" APPDIR vshelper) || _vgh_appdir=
+
+    declare -a _vgh_search_list=( X )
     ## HACK: when we are in 'set -u' mode, empty lists are causing errors
 
-    test -z "$appdir" || search_list=( "${search_list[@]}" -x "$appdir/$3" )
-    test -z "$appdir" || search_list=( "${search_list[@]}" -e "$appdir/action" )
-    search_list=( "${search_list[@]}" -x "$CONFDIR"/.defaults/apps/vshelper/"$3" )
-    search_list=( "${search_list[@]}" -e "$CONFDIR"/.defaults/apps/vshelper/action )
+    test -z "$_vgh_appdir" || _vgh_search_list=( "${_vgh_search_list[@]}" -x "$_vgh_appdir/$3" )
+    test -z "$_vgh_appdir" || _vgh_search_list=( "${_vgh_search_list[@]}" -e "$_vgh_appdir/action" )
+    _vgh_search_list=( "${_vgh_search_list[@]}" -x "$__CONFDIR"/.defaults/apps/vshelper/"$3" )
+    _vgh_search_list=( "${_vgh_search_list[@]}" -e "$__CONFDIR"/.defaults/apps/vshelper/action )
 
-    ! vshelper._getHandlerInternal "$1" "${search_list[@]}" || return 0
+    ! vshelper._getHandlerInternal "$1" "${_vgh_search_list[@]}" || return 0
     eval $1=':restart'
 }
 
@@ -738,19 +808,20 @@ function vshelper.doInit
 {
     vshelper.isEnabled || return 0
     
-    local xid=$($_VSERVER_INFO "$1" CONTEXT false) && test "$xid" || {
+    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'"
        return 1
     }
 
-    local f="$VSHELPERSTATEDIR/$xid"
+    local f="$__VSHELPERSTATEDIR/$xid"
     
     set -C
-    rm -f "$f"
+    $_RM -f "$f"
     echo "$1" >"$f"
     set +C
     
-    if test "$2"; then
+    if test -n "$2"; then
        shift 1
        local i
        for i; do
@@ -768,31 +839,79 @@ function vshelper.doDestroy
 {
     vshelper.isEnabled || return 0
 
-    rm -f "$VSHELPERSTATEDIR/$2"
+    $_RM -f "$__VSHELPERSTATEDIR/$2"
 }
 
 ## Usage: vshelper.initSync <vserver> <pipe-varname>
 function vshelper.initSync
 {
-    local tmpdir=$(mktemp -d /tmp/vserver-stop.XXXXXX) || {
+    local _vis_tmpdir
+    _vis_tmpdir=$($_MKTEMPDIR /tmp/vserver-stop.XXXXXX) || {
        warning $"Failed to generate temporary directory for vshelper sync"
        return 1
     }
 
-    local fifo="$tmpdir"/pipe
-    mkfifo -m700 "$fifo"
-    vshelper.doInit "$1" sync "$fifo"
-    eval $2=\$fifo
+    local _vis_fifo="$_vis_tmpdir"/pipe
+    $_MKFIFO -m700 "$_vis_fifo"
+    vshelper.doInit "$1" sync "$_vis_fifo"
+    eval $2=\$_vis_fifo
 }
 
 ## Usage: vshelper.getSyncTimeout <vserver> <varname>
 function vshelper.getSyncTimeout
 {
-    local appdir=$($_VSERVER_INFO "$1" APPDIR vshelper) || appdir=
-    local file tmp
+    local _vgst_appdir _vgst_file _vgst_tmp
+    _vgst_appdir=$($_VSERVER_INFO "$1" APPDIR vshelper) || _vgst_appdir=
+
+    findFile _vgst_file ${_vgst_appdir:+"$_vgst_appdir"/sync-timeout} "$__CONFDIR"/.defaults/apps/vshelper/sync-timeout ''
+    test -n "$_vgst_file" || return 1
+    read _vgst_tmp <"$_vgst_file"
+    eval $2=\$_vgst_tmp
+}
+
+
+function _rpmFake.getCapFlags
+{
+    local ctx=$1
+    
+    if test -n "$ctx" && ! $_VSERVER_INFO - FEATURE migrate; then
+       set -- $($_CHCONTEXT_COMPAT --xid 1 \
+           $_SH -c "$_CAT /proc/[0-9]*/status | $_EGREP '^(CapBset|s_context|ctxflags)'" | \
+           $_GREP -B 1 -A 1 "^s_context: $ctx " | \
+           $_SED -e '1,3p;d' | $_AWK '{ print $2 }')
+    else
+       set --
+    fi
+
+    if test -n "$3"; then
+       RPM_FAKE_CAP=$[ ~0x$1 ]
+       RPM_FAKE_FLAGS=$3
+    else
+       RPM_FAKE_CAP=$[ ~0xd40c04ff ]
+       RPM_FAKE_FLAGS=4
+    fi
+}
+
+function rpmFake.init
+{
+    local vdir ctx
+    
+    vdir=$($_VSERVER_INFO "$1" VDIR)    || vdir="$1"
+    ctx=$($_VSERVER_INFO  "$1" CONTEXT) || ctx=
+
+    test -d "$vdir" ||
+       panic $"Can not find chroot environment at '$vdir' for '$1'"
+
+    _rpmFake.getCapFlags "$ctx"
 
-    findFile file ${appdir:+"$appdir"/sync-timeout} "$CONFDIR"/.defaults/apps/vshelper/sync-timeout ''
-    test "$file" || return 1
-    read tmp <"$file"
-    eval $2=\$tmp
+    RPM_FAKE_CHROOT=$vdir
+    RPM_FAKE_CTX=$ctx
+}
+
+function rpmFake.exec
+{
+    export RPM_FAKE_CHROOT RPM_FAKE_CTX RPM_FAKE_CAP RPM_FAKE_FLAGS
+    
+    LD_PRELOAD=$_RPM_FAKE_SO${LD_PRELOAD:+:$LD_PRELOAD} \
+       exec "$@"
 }