added '--defaulttty' option
[util-vserver.git] / util-vserver / scripts / functions
index d3a2c40..0fe56c9 100644 (file)
@@ -127,9 +127,8 @@ function lock
     rm -f $tmp
     mkfifo -m600 $tmp
 
-    sleep 10
     $_LOCKFILE "$1" $tmp $2 &
-    cat <$tmp >/dev/null
+    grep -q true $tmp 2>/dev/null || return 1
     
     _VS_LOCKS="$! $_VS_LOCKS"
 }
@@ -452,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
@@ -462,6 +461,22 @@ function callInNamespace
     fi
 }
 
+## Usage: setDefaultTTY <vdir> [<fallback-tty>]
+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 <vserver> <resultvar>
 function pkgmgmt.guessStyle()
 {
@@ -561,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
     }
 
@@ -665,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
     }