killContext(): commented out the more correct
[util-vserver.git] / util-vserver / scripts / functions
index 77e30e0..6b89210 100644 (file)
@@ -111,6 +111,14 @@ function execute
     exit 0
 }
 
+
+## Usage: spawn <message>
+function spawn
+{
+    test -z "${DEBUG_EXEC:-}"       || echo  "$@"
+    test "${DEBUG_EXEC:-}" = noexec || "$@"
+}
+
 ## Usage: isNumber <arg>
 function isNumber
 {
@@ -129,7 +137,7 @@ function colorize
        "$@"
     else
        local   cfile
-       findFile cfile "$CONFDIR"/.defaults/styles/"$style" ''
+       findFile cfile "$__CONFDIR"/.defaults/styles/"$style" ''
        if test -n "$cfile"; then
          $_CAT "$cfile"
        else
@@ -212,14 +220,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
@@ -393,7 +401,7 @@ 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
 }
 
@@ -402,7 +410,7 @@ function getAllVservers
     local _ga_i
     declare -a _ga_tmp=()
 
-    for _ga_i in $CONFDIR/*; do
+    for _ga_i in $__CONFDIR/*; do
        test   -d "$_ga_i"          || continue
        test ! -e "$_ga_i"/disabled || continue
        test   -d "$_ga_i"/vdir     || continue
@@ -410,7 +418,7 @@ function getAllVservers
            *.~*~) continue;;
        esac
 
-       _ga_tmp=( "${_ga_tmp[@]}" "${_ga_i##$CONFDIR/}")
+       _ga_tmp=( "${_ga_tmp[@]}" "${_ga_i##$__CONFDIR/}")
     done
 
     eval $1='( "${_ga_tmp[@]}" )'
@@ -511,8 +519,8 @@ function checkComponents
        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;;
+           (sysv)      test -x "$__INITRDDIR/vserver"    || failed=1;;
+           (devel)     test -d "$__INCLUDEDIR/vserver.h" || failed=1;;
            (*)         echo "Unknown component '$i'" >&2
                        return false
                        ;;
@@ -559,13 +567,25 @@ 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
     exec  &>$ttyname
 }
 
+## Usage: killContext <XID> [<SIG>]
+function killContext
+{
+    local sig=${2:-9}
+
+    #$_VKILL -s STOP   --xid "$1" 1 &>/dev/null || :
+    $_VKILL -s "$sig" --xid "$1" 1 &>/dev/null || :
+    $_VKILL -s "$sig" --xid "$1"   &>/dev/null || :
+    #$_VKILL -s "$sig" --xid "$1" 1 &>/dev/null || :
+    #$_VKILL -s CONT   --xid "$1" 1 &>/dev/null || :
+}
+
 ## Usage: pkgmgmt.guessStyle <vserver> <resultvar>
 function pkgmgmt.guessStyle()
 {
@@ -670,7 +690,7 @@ 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")
@@ -685,10 +705,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
@@ -709,9 +729,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
@@ -731,7 +751,7 @@ 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 -n "$2"; then
        local appdir
@@ -745,15 +765,15 @@ function vshelper.isEnabled
 ## Usage: vshelper.isDebug [<vserver>]
 function vshelper.isDebug
 {
-    test ! -e "$CONFDIR"/.defaults/apps/vshelper/debug     || return 1
+    test ! -e "$__CONFDIR"/.defaults/apps/vshelper/debug    || return 0
     $_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
+       test ! -e "$appdir/debug"                           || return 0
     fi
 
-    return 0
+    return 1
 }
 
 function vshelper._getHandlerInternal
@@ -796,8 +816,8 @@ function vshelper.getHandler
 
     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 )
+    _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" "${_vgh_search_list[@]}" || return 0
     eval $1=':restart'
@@ -814,7 +834,7 @@ function vshelper.doInit
        return 1
     }
 
-    local f="$VSHELPERSTATEDIR/$xid"
+    local f="$__VSHELPERSTATEDIR/$xid"
     
     set -C
     $_RM -f "$f"
@@ -839,10 +859,10 @@ function vshelper.doDestroy
 {
     vshelper.isEnabled || return 0
 
-    $_RM -f "$VSHELPERSTATEDIR/$2"
+    $_RM -f "$__VSHELPERSTATEDIR/$2"
 }
 
-## Usage: vshelper.initSync <vserver> <pipe-varname>
+## Usage: vshelper.initSync <vserver> <pipe-varname> [<method>]
 function vshelper.initSync
 {
     local _vis_tmpdir
@@ -853,7 +873,7 @@ function vshelper.initSync
 
     local _vis_fifo="$_vis_tmpdir"/pipe
     $_MKFIFO -m700 "$_vis_fifo"
-    vshelper.doInit "$1" sync "$_vis_fifo"
+    vshelper.doInit "$1" "${method:-sync}" "$_vis_fifo"
     eval $2=\$_vis_fifo
 }
 
@@ -863,7 +883,7 @@ function vshelper.getSyncTimeout
     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 ''
+    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