X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Fscripts%2Ffunctions;h=c4d873bd0b8cb004ba0485057e33f9d5461c9b04;hb=63052a3fcbb92d0c65c515ee0918ccb6467938a3;hp=35d25e6df7e04e1744191c70a755bf192bfafc7e;hpb=de848176d34617bb2d80cc9bfac75c373f029118;p=util-vserver.git diff --git a/util-vserver/scripts/functions b/util-vserver/scripts/functions index 35d25e6..c4d873b 100644 --- a/util-vserver/scripts/functions +++ b/util-vserver/scripts/functions @@ -242,10 +242,13 @@ function pkgInit function isAvoidNamespace { - $_VSERVER_INFO - FEATURE namespace || return 1 - test ! -e "$1"/namespace || return 1 + local cfgdir + + $_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 \ - -e "$1"/nonamespace + -e "$cfgdir"/nonamespace } function getAllVservers @@ -268,6 +271,7 @@ function getAllVservers } ## Usage: getVserverCtx [ []] +## Returns: 0 iff vserver is running function getVserverStatus { test -r "$1"/run || return 1 @@ -278,12 +282,15 @@ function getVserverStatus test "$3" || return 0 local _tmp=$($_VPS ax | $_AWK '{print $2}' | $_GREP -x "$_ctx" | $_WC -l ) + let _tmp=_tmp+0 eval "$3"=\$_tmp - test "$4" -a $_tmp = 0 || return 0 - _tmp=$($_READLINK "$1/run") - test "$_tmp" || return 1 - rm -f "$_tmp" + if test "$_tmp" = 0; then + local runfile=$($_READLINK "$1/run") + test -z "$4" || rm -f "$runfile" + return 1 + fi + return 0 } @@ -356,3 +363,57 @@ function isKernelAPI local api=$($_VSERVER_INFO - APIVER) || api=0 test $[ $api ] -${2:-ge} $[ $1 ] } + +## Usage: callInNamespace * +function callInNamespace +{ + local ctx= + + isAvoidNamespace "$1" || \ + ctx=$( $_VSERVER_INFO "$1" CONTEXT t ) || ctx= + + shift + if test "$ctx"; then + $_VNAMESPACE --enter "$ctx" -- "$@" + else + "$@" + fi +} + +## Usage: pkgmgmt.guessStyle +function pkgmgmt.guessStyle() +{ + local vdir=$($_VSERVER_INFO "$1" VDIR) || { + echo $"Can not determine vserver-root" >&2 + return 1 + } + local 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 + style=redhat + elif test -e "$vdir"/etc/mandrake-release; then + style=mandrake + elif test -e "$vdir"/etc/debian_version; then + style=debian + else + echo $"Can not determine packagemanagement style" >&2 + return 1 + fi + + eval $2=\$style + return 0 +} + +## Usage: pkgmgmt.isInternal +## returns true iff is configured for internal packagemanagement +## A typical application is +## | is_external= +## | pkgmgmt.isInternal "$vserver" || is_external=1 +function pkgmgmt.isInternal +{ + local cfgdir=$($_VSERVER_INFO "$1" APPDIR pkgmgmt) || : + + test -z "$cfgdir" -o ! -d "$cfgdir" -o -e "$cfgdir"/internal +}