X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=util-vserver%2Fscripts%2Ffunctions;h=0fe56c91bd03d9f6b5b95d2862c1ccc20519fded;hb=e4d856b46bea4c1ace17edbc7eb4b5e30385ac9d;hp=c664f2f76af6d8ae4d856fc2a367628b6ad2df81;hpb=3b1a17178d25187b0afbf1926c29ae52253bc02e;p=util-vserver.git diff --git a/util-vserver/scripts/functions b/util-vserver/scripts/functions index c664f2f..0fe56c9 100644 --- a/util-vserver/scripts/functions +++ b/util-vserver/scripts/functions @@ -71,6 +71,7 @@ function getPhysicalDir ( set -P && cd "$1" && pwd ) } +## Usage: logging function logging { if test "$_VS_LOGFILE"; then @@ -80,6 +81,7 @@ function logging fi } +## Usage: warning function warning { if test "$_VS_ERRFILE"; then @@ -89,6 +91,7 @@ function warning fi } +## Usage: panic function panic { if test "$_VS_ERRFILE"; then @@ -100,6 +103,7 @@ function panic exit 1 } +## Usage: execute function execute { test -z "${DEBUG_EXEC:-}" || echo "$@" @@ -107,6 +111,7 @@ function execute exit 0 } +## Usage: isNumber function isNumber { local tmp @@ -114,6 +119,36 @@ function isNumber return 0 } +_VS_LOCKS='' +## Usage: lock [] +function lock +{ + 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 + + _VS_LOCKS="$! $_VS_LOCKS" +} + +## Usage: unlock [] +function unlock +{ + local num=$1 + local i + + set -- $_VS_LOCKS + while test "$#" -gt 0; do + kill -HUP "$1" >/dev/null || : + shift + test "$num" != 1 || break + test -z "$num" || let --num + done + _VS_LOCKS="$@" +} + function _pkgMountBindDir() { test "$1" != "$2" || return 0 @@ -416,7 +451,7 @@ function callInNamespace local ctx= isAvoidNamespace "$1" || \ - ctx=$( $_VSERVER_INFO "$1" CONTEXT t ) || ctx= + ctx=$( $_VSERVER_INFO "$1" CONTEXT f ) || ctx= shift if test "$ctx"; then @@ -426,6 +461,22 @@ function callInNamespace fi } +## Usage: setDefaultTTY [] +function setDefaultTTY +{ + local cfgdir ttyname + + cfgdir=$($_VSERVER_INFO "$1" APPDIR init) || cfgdir= + findObject -e ttyname \ + ${cfgdir:+"$cfgdir"/tty} \ + "$CONFDIR/.defaults/apps/init/tty" \ + $2 /dev/null + + exec <$ttyname + exec >>$ttyname + exec 2>>$ttyname +} + ## Usage: pkgmgmt.guessStyle function pkgmgmt.guessStyle() { @@ -525,9 +576,9 @@ function vshelper.doSanityCheck test -d "$VSHELPERSTATEDIR" || { warnings=( "${warnings[@]}" $"\ -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" ) +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 } @@ -629,8 +680,8 @@ function vshelper.doInit { vshelper.isEnabled || return 0 - local xid=$($_VSERVER_INFO "$1" CONTEXT false) || { - warning $"vshelper.init: can not determine xid of vserver '$vserver'" + local xid=$($_VSERVER_INFO "$1" CONTEXT false) && test "$xid" || { + warning $"vshelper.init: can not determine xid of vserver '$vserver'; returned value was '$xid'" return 1 }