3 # Copyright (C) 2003,2004,2005,2006 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; version 2 of the License.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 declare -r _VS_NEWLINE=${_VS_NEWLINE:0-1}
34 test -n "$_fo_i" || continue
35 test ! $_fo_mod "$_fo_i" || { _fo_file=$_fo_i; break; }
38 test -z "$_fo_i" -o -n "$_fo_file" || {
39 echo "Can not find file for '$_fo_var'; aborting"
43 eval "$_fo_var=\"$_fo_file\""
59 test ! -s "$dst" || return 0
65 test -n "$tmp" -a -s "$tmp" || return 0
66 $_CP -af "$tmp" "$dst"
69 ## Usage: isRegularFile <filename> [<mod>]
70 function isRegularFile
72 test ${2:--f} "$1" || return 1
75 (*.rpmsave|*.rpmnew|*.rpmorig|*.cfsaved*|*.~*~) return 1;;
81 function getPhysicalDir
83 ( set -P && cd "$1" && pwd )
86 ## Usage:: isDirectoryEmpty <dir> [<ignore-lost+found>]
87 function isDirectoryEmpty
91 shopt -s nullglob || *
94 test -z "$2" -o "$2" = 0 || ignore_lostfound=
99 test "$ignore_lostfound" || exit 1
101 (*) echo "$i"; exit 1
109 ## Usage: logging <message>
112 if test -n "$_VS_LOGFILE"; then
113 echo "$@" >>"$_VS_LOGFILE"
119 ## Usage: warning <message>
122 if test -n "$_VS_ERRFILE"; then
123 echo "$@" >>"$_VS_ERRFILE"
129 ## Usage: panic <message>
132 if test -n "$_VS_ERRFILE"; then
133 echo "$@" >>"$_VS_ERRFILE"
141 ## Usage: execute <message>
144 test -z "${DEBUG_EXEC:-}" || echo "$@"
145 test "${DEBUG_EXEC:-}" = noexec || exec "$@"
150 ## Usage: spawn <message>
153 test -z "${DEBUG_EXEC:-}" || echo "$@"
154 test "${DEBUG_EXEC:-}" = noexec || "$@"
157 ## Usage: isNumber <arg>
161 let tmp=$1+0 2>/dev/null || test -z "${1//0/}" -a -n "$1" || return 1
165 ## Usage: hasSubstring <haystack> <needle>+
166 function hasSubstring
174 test x"${pat/*$i*/$i}" = x"$i" || continue
181 ## Usage: colorize <style> <command>
191 findFile cfile "$__CONFDIR"/.defaults/styles/"$style" ''
192 if test -n "$cfile"; then
196 (bold) echo -ne "\e[1m";;
197 (emph) echo -ne "\e[34m";;
198 (info) echo -ne "\e[0;34m";;
199 (warn*) echo -ne "\e[1;31m";;
200 (error) echo -ne "\e[1;33;41m";;
212 if test -n "$_VS_ERRFILE"; then
213 echo "$@" >>"$_VS_ERRFILE"
215 colorize error echo -n "$@" >&2
224 colorize warning warning "$@"
229 colorize info echo "$@"
233 ## Usage: xtermTitle <title>
237 echo -ne "\e]0;$@\007"
241 ## Usage: lock <lockfile> [<timeout>]
244 local tmp=$($_MKTEMP vserver-lock.XXXXXX)
248 $_LOCKFILE "$1" $tmp $2 &
249 $_GREP -q true $tmp 2>/dev/null || return 1
251 _VS_LOCKS="$! $_VS_LOCKS"
254 ## Usage: unlock [<num>]
261 while test "$#" -gt 0; do
262 kill -HUP "$1" >/dev/null || :
264 test "$num" != 1 || break
265 test -z "$num" || let --num
270 function get_init_cwd
272 if test -n "$INIT_CWD"; then
278 function set_init_cwd
284 function _setVserverDir
288 ./*) VSERVER_DIR="`get_init_cwd`/$vserver";;
289 /*) VSERVER_DIR="$vserver" ;;
290 *) VSERVER_DIR="$__CONFDIR/$vserver" ;;
294 function _setVserverName
296 VSERVER_NAME=$(basename "$VSERVER_DIR")
299 function _pkgMountBindDir()
301 test "$1" != "$2" || return 0
303 $_MOUNT -n --bind "$1" "$2"
306 function _pkgSetVarsBase
310 if test -d "$vserver/vdir"; then
312 VDIR=$(getPhysicalDir "$vserver/vdir")
314 PKGDIR=$BASEDIR/apps/pkgmgmt
315 test -d "$PKGDIR" || {
316 echo "Can not find configuration-directory for package-managment tools"
319 findDir EXECDIR $PKGDIR/execdir /
321 VDIR=$(getPhysicalDir "$vserver")
326 BASEDIR=$__CONFDIR/$vserver
327 test -d "$BASEDIR" || {
328 echo "Can not find configuration-directory"
333 test -d "$VDIR" || VDIR=$__DEFAULT_VSERVERDIR/$vserver
334 VDIR=$(getPhysicalDir "$VDIR")
336 PKGDIR=$BASEDIR/apps/pkgmgmt
337 test -d "$PKGDIR" || {
338 echo "Can not find configuration-directory for package-managment tools"
342 findDir EXECDIR $PKGDIR/execdir /
347 if test -z "$WORKAROUND_106057"; then
350 _rpmdb_mntpoint=/.rpmdb
354 function _pkgSetVarsRPM
356 if test -n "$PKGDIR"; then
357 findDir RPMETCDIR $PKGDIR/rpmetc $PKGDIR/base/rpm/etc /etc/rpm
358 findDir RPMSTATEDIR $PKGDIR/rpmstate $PKGDIR/base/rpm/state
360 findDir RPMLIBDIR $PKGDIR/rpmlib /
363 findDir RPMETCDIR "$VDIR"/etc/rpm /etc/rpm
364 findDir RPMSTATEDIR "$VDIR"/var/lib/rpm
368 RPMSTATEDIR=$(getPhysicalDir "$RPMSTATEDIR")
369 RPMETCDIR=$(getPhysicalDir "$RPMETCDIR")
372 function _pkgSetVarsApt
374 if test -n "$PKGDIR"; then
375 findDir APTETCDIR $PKGDIR/aptetc $PKGDIR/base/apt/etc /etc/apt
376 findDir APTSTATEDIR $PKGDIR/aptstate $PKGDIR/base/apt/state
377 findDir APTCACHEDIR $PKGDIR/aptcache $PKGDIR/base/apt/cache
378 findDir APTARCHIVDIR $PKGDIR/aptarchives $PKGDIR/base/apt/archives /var/cache/apt/archives
380 findDir APTETCDIR "$VDIR"/etc/apt /etc/apt
381 findDir APTSTATEDIR "$VDIR"/var/state/apt
382 findDir APTCACHEDIR "$VDIR"/var/cache/apt
383 findDir APTARCHIVDIR "$VDIR"/var/cache/apt/archives /var/cache/apt/archives
386 findFile APT_CONFIG "$APTETCDIR"/apt.conf ""
387 test -z "$APT_CONFIG" || export APT_CONFIG
390 function _pkgSetVarsYum
392 if test -n "$PKGDIR"; then
393 findDir YUMETCDIR $PKGDIR/yumetc $PKGDIR/base/yum/etc /etc
394 findDir YUMCACHEDIR $PKGDIR/yumcache $PKGDIR/base/yum/cache
396 findDir YUMETCDIR "$VDIR"/etc /etc
397 findDir YUMCACHEDIR "$VDIR"/var/cache/yum
402 function _pkgMountBase
407 function _pkgMountApt
412 function _pkgMountYum
417 function _pkgMountRPM
419 _pkgMountBindDir "$RPMETCDIR" /etc/rpm
420 test "$RPMLIBDIR" = "/" || _pkgMountBindDir "$RPMLIBDIR" /usr/lib/rpm
422 pushd "$VDIR" >/dev/null
424 $_SECURE_MOUNT --chroot -n --bind "$RPMSTATEDIR" "$_rpmdb_mntpoint"
425 test -z "$WORKAROUND_106057" || mount -n --bind "$RPMSTATEDIR" "$_rpmdb_mntpoint"
427 test -e "$VDIR"/proc/self/status || \
428 $_SECURE_MOUNT --chroot -n -t proc none /proc
433 function _pkgSetEnvBase
435 test "$EXECDIR" = "/" || {
437 LD_LIBRARY_PATH=$EXECDIR${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
440 export PATH LD_LIBRARY_PATH
443 function _pkgSetEnvApt
448 function _pkgSetEnvYum
453 function _pkgSetEnvRPM
456 RPM_FAKE_NAMESPACE_MOUNTS=$_rpmdb_mntpoint
457 RPM_BINARY=$_VRPM_PRELOAD
459 export CUR_VSERVER RPM_FAKE_NAMESPACE_MOUNTS RPM_BINARY
471 rpm) _pkgSetVarsRPM;;
472 apt) _pkgSetVarsApt;;
473 yum) _pkgSetVarsYum;;
474 *) echo "Unknown packaging flavor" >&2; exit 1;;
497 _PKG_VSERVER=$vserver
500 function isAvoidNamespace
504 $_VSERVER_INFO - FEATURE namespace || return 0
505 cfgdir=$($_VSERVER_INFO "$1" CFGDIR) || return 0
506 test ! -e "$cfgdir"/namespace || return 1
507 test -e "$__CONFDIR"/.defaults/nonamespace -o \
508 -e "$cfgdir"/nonamespace
511 function isNamespaceCleanup
515 $_VSERVER_INFO - FEATURE namespace || return 1
516 cfgdir=$($_VSERVER_INFO "$1" CFGDIR) || return 1
517 isAvoidNamespace "$1" && return 1
518 test -e "$cfgdir"/namespace-cleanup && return 0
519 test -e "$cfgdir"/nonamespace-cleanup -o \
520 -e "$__CONFDIR"/.defaults/nonamespace-cleanup && return 1
524 ## Usage: getAllVservers <var> [<KIND>*]
525 function getAllVservers
528 declare -a _ga_tmp=()
530 for _ga_i in $__CONFDIR/*; do
531 isRegularFile "$_ga_i" -d || continue
533 test ! -e "$_ga_i"/disabled || continue
534 test -d "$_ga_i"/vdir || continue
537 local _ga_markfile=$_ga_i/apps/init/mark
540 (MARKED) test -s "$_ga_markfile" || _ga_doadd=;;
541 (UNMARKED) test ! -s "$_ga_markfile" || _ga_doadd=;;
542 (STOPPED) ! $_VSERVER "$_ga_i" running &>/dev/null || _ga_doadd=;;
543 (RUNNING) $_VSERVER "$_ga_i" running &>/dev/null || _ga_doadd=;;
545 (MARK) test -s "$_ga_markfile" && grep -qx "$3" "$_ga_markfile" || _ga_doadd=;;
546 (*) panic $"Unknown vserver tagging '$2'";;
549 test -z "$_ga_doadd" || _ga_tmp=( "${_ga_tmp[@]}" "${_ga_i##$__CONFDIR/}")
552 eval $1='( "${_ga_tmp[@]}" )'
555 declare -r VS_ALLVSERVERS_ARGS=all,marked,unmarked,stopped,running,mark:
556 ## Usage: getAllVserversByArg <var> <arg>
557 function getAllVserversByArg
565 while test "$#" -ge 1; do
570 (--all) _gav_mark=ALL;;
571 (--marked) _gav_mark=MARKED;;
572 (--unmarked) _gav_mark=UNMARKED;;
573 (--stopped) _gav_mark=STOPPED;;
574 (--running) _gav_mark=RUNNING;;
575 (--mark*) _gav_mark=MARK
576 _gav_extra=${_gav_i##*=}
577 test -n "$_gav_extra" -a "$_gav_extra" != "--mark" || \
582 (*) set -- "$_gav_v" "$@"
586 getAllVservers _gav_tmp "$_gav_mark" $_gav_extra
587 if test -n "$_gav_first"; then
588 _gav_res=( "${_gav_tmp[@]}" )
591 while test $_gav_i -lt "${#_gav_res[@]}"; do
593 for _gav_j in "${_gav_tmp[@]}"; do
594 if test "$_gav_j" = "${_gav_res[$_gav_i]}"; then
599 if test "$_gav_found" = 0; then
600 unset _gav_res[$_gav_i]
604 _gav_res=( "${_gav_res[@]}" )
609 eval $_gav_v='( "${_gav_res[@]}" )'
612 ## Usage: _getProcNumberCount <ctx> <var>
613 function _getProcNumberCount
616 local _gp_procnr_cnt=0
618 # Use /proc/virtual from kernel 2.6 when possible
619 if test -d "/proc/virtual"; then
620 set -- $($_GREP '^Tasks:' "/proc/virtual/$1/status" 2>/dev/null)
623 _gp_procnr_cnt=$($_VPS ax | $_AWK '{print $2}' | $_GREP -x "$1" | $_WC -l )
626 let _gp_procnr_cnt=_gp_procnr_cnt+0
627 eval $_gp_var=\$_gp_procnr_cnt
630 ## Usage: getVserverCtx <vdir> <result-varname> [<procnumber-varname> [<do-cleanup>]]
631 ## Returns: 0 iff vserver is running
632 function getVserverStatus
634 test -r "$1"/run || return 1
637 read _gvs_ctx <"$1"/run
640 if test "$1" = "$($_VUNAME -g --xid "$_gvs_ctx" context)"; then
641 test -n "$3" || return 0
643 _getProcNumberCount "$_gvs_ctx" _gvs_tmp
646 test -n "$3" || return 1
651 if test "$_gvs_tmp" = 0; then
652 local runfile=$($_READLINK "$1/run")
653 test -z "$4" || $_RM -f "$runfile"
660 ## Usage: isCtxRunning <ctx>
661 function isCtxRunning
664 _getProcNumberCount "$1" _tmp
668 ## Usage: isVserverRunning <vdir> [<ctx-varname>]
669 function isVserverRunning
671 local _ivr_ctx _ivr_procnum
673 getVserverStatus "$1" _ivr_ctx _ivr_procnum 1 || return 1
674 test "$_ivr_procnum" != 0 || return 1
675 test -z "$2" || eval "$2"=\$_ivr_ctx
679 ## Called as 'getFileValue <varname> <filename>+'
680 function getFileValue
686 findFile _gfv_file "$@" ''
687 test -n "$_gfv_file" -a -r "$_gfv_file" || return 0
688 eval read "$_gfv_var" <"$_gfv_file"
691 ## Called as 'getFileArray <varname> <filename>+'
692 function getFileArray
698 findFile _gfa_file "$@" ''
699 test -n "$_gfa_file" -a -r "$_gfa_file" || return 0
700 local IFS=$_VS_NEWLINE
701 eval "$_gfa_var"='( $(< "$_gfa_file") )'
704 function checkComponents
715 (core) test -x "$_CHBIND" || failed=1;;
716 (build) test -x "$_VSERVER_BUILD" || failed=1;;
717 (sysv) test -x "$__INITRDDIR/vserver" || failed=1;;
718 (devel) test -d "$__INCLUDEDIR/vserver.h" || failed=1;;
719 (*) echo "Unknown component '$i'" >&2
724 test -z "$failed" || {
733 ## Usage: isKernelAPI <ver> [<cmp-modifier>]
737 api=$($_VSERVER_INFO - APIVER) || api=0
738 test $[ $api ] -${2:-ge} $[ $1 ]
741 ## Usage: callInNamespace <vserver> <command> <args>*
742 function callInNamespace
746 isAvoidNamespace "$1" || \
747 ctx=$( $_VSERVER_INFO "$1" CONTEXT f ) || ctx=
750 if test -n "$ctx"; then
751 $_VNAMESPACE --enter "$ctx" -- "$@"
757 ## Usage: setDefaultTTY <vdir> [<fallback-tty>]
758 function setDefaultTTY
762 cfgdir=$($_VSERVER_INFO "$1" APPDIR init) || cfgdir=
763 findObject -e ttyname \
764 ${cfgdir:+"$cfgdir"/tty} \
765 "$__CONFDIR/.defaults/apps/init/tty" \
768 if test -f "$ttyname"; then
776 ## Usage: killContext <XID> [<SIG>]
781 #$_VKILL -s STOP --xid "$1" 1 &>/dev/null || :
782 $_VKILL -s "$sig" --xid "$1" 1 &>/dev/null || :
783 $_VKILL -s "$sig" --xid "$1" &>/dev/null || :
784 #$_VKILL -s "$sig" --xid "$1" 1 &>/dev/null || :
785 #$_VKILL -s CONT --xid "$1" 1 &>/dev/null || :
790 test ! -e "$__CONFDIR/.defaults/apps/vlogin/disable"
793 ## Usage: pkgmgmt.guessStyle <vserver> <resultvar>
794 function pkgmgmt.guessStyle()
797 _pgs_vdir=$($_VSERVER_INFO "$1" VDIR) || {
798 echo $"Can not determine vserver-root" >&2
801 local _pgs_cfgdir=$($_VSERVER_INFO "$1" APPDIR pkgmgmt) || :
803 if test -n "$_pgs_cfgdir" -a -e "$_pgs_cfgdir"/style; then
804 read style <"$_pgs_cfgdir"/style
805 elif test -e "$_pgs_vdir"/etc/redhat-release -o -e "$_pgs_vdir"/etc/fedora-release; then
807 elif test -e "$_pgs_vdir"/etc/mandrake-release; then
809 elif test -e "$_pgs_vdir"/etc/debian_version; then
811 elif test -e "$_pgs_vdir"/etc/SuSE-release; then
814 echo $"Can not determine packagemanagement style" >&2
822 ## Usage: pkgmgmt.isInternal <vserver>
823 ## returns true iff <vserver> is configured for internal packagemanagement
824 ## A typical application is
826 ## | pkgmgmt.isInternal "$vserver" || is_external=1
827 function pkgmgmt.isInternal
829 local cfgdir=$($_VSERVER_INFO "$1" APPDIR pkgmgmt) || :
831 test -z "$cfgdir" -o ! -d "$cfgdir" -o -e "$cfgdir"/internal
834 ## Usage: pkgmgmt.isAptAvailable <cfgdir> <vdir> [<is-internal>]
835 function pkgmgmt.isAptAvailable
839 local is_internal="$3"
842 if test -n "$is_internal"; then
844 test -d "$cfgdir"/base/apt -o -d "$cfgdir"/aptetc || have_apt=
847 for i in /bin /usr/bin /usr/local/bin; do
848 test ! -x "$vdir$i"/apt-get || { have_apt=1; break; }
852 test -n "$have_apt" && return 0 || return 1
855 ## Usage: pkgmgmt.isYumAvailable <cfgdir> <vdir> [<is-internal>]
856 function pkgmgmt.isYumAvailable
860 local is_internal="$3"
863 if test -n "$is_internal"; then
865 test -d "$cfgdir"/base/yum -o -d "$cfgdir"/yumetc || have_yum=
868 for i in /bin /usr/bin /usr/local/bin; do
869 test ! -x "$vdir$i"/yum || { have_yum=1; break; }
873 test -n "$have_yum" && return 0 || return 1
877 function vshelper.doSanityCheck
879 local vshelper this_xid i
880 declare -a warnings=()
881 local solution_disable=
882 local solution_sysctl=
884 vshelper.isEnabled && vshelper.isEnabled warning || return 0
886 this_xid=$($_VSERVER_INFO - XID) ||
887 panic $"Failed to determine current context; aborting..."
889 ## Do nothing in other xid's; the helper will be executed in xid 0 only
890 test "$this_xid" = 0 || return 0
892 local proc_file=/proc/sys/kernel/vshelper
894 if ! test -r "$proc_file"; then
896 warnings=( "${warnings[@]}"
897 $"File '$proc_file' does not exist but is required for vshelper setup" )
900 vshelper=$(cat "$proc_file")
902 $_CMP -s "$vshelper" "$_VSHELPER" || {
904 test -r "$vshelper" && readable=1
905 warnings=( "${warnings[@]}"
906 $"The configured vshelper '$vshelper' does not match the 'vshelper'
907 script of the util-vserver package.${readable:+ Maybe you have two versions installed?}"
914 test -d "$__VSHELPERSTATEDIR" || {
915 warnings=( "${warnings[@]}"
917 The vshelper state-directory '$__VSHELPERSTATEDIR' does not exist; since
918 it is created by 'make install', this indicates a serious problem with
919 your util-vserver installation" )
923 test "${#warnings[@]}" -eq 0 || {
925 The following problem(s) were encountered while verifying vshelper
928 for i in "${warnings[@]}"; do
934 To fix this, you can:"
936 test -z "$solution_disable" || warning $"\
937 * disable vshelper entirely by executing
938 | touch \"$__CONFDIR/.defaults/apps/vshelper/disabled\"
939 * disable only this message by executing
940 | touch \"$__CONFDIR/.defaults/apps/vshelper/warning-disabled\""
942 test -x "$solution_sysctl" || warning $"\
943 * configure the util-vserver vshelper script, e.g. by adding
944 | kernel.vshelper = $_VSHELPER
945 to /etc/sysctl.conf and rebooting the machine, or by executing
946 | echo \"$_VSHELPER\" >$proc_file"
956 ## Usage: vshelper.isEnabled [<style>] [<vserver>]
957 function vshelper.isEnabled
959 local f=${1:+$1-}disabled
960 test ! -e "$__CONFDIR"/.defaults/apps/vshelper/"$f" || return 1
961 $_VSERVER_INFO - FEATURE vshelper || return 1
962 if test -n "$2"; then
964 appdir=$($_VSERVER_INFO "$2" APPDIR vshelper) || return 0
965 test -z "$2" -o ! -e "$appdir/$f" || return 1
971 ## Usage: vshelper.isDebug [<vserver>]
972 function vshelper.isDebug
974 test ! -e "$__CONFDIR"/.defaults/apps/vshelper/debug || return 0
975 $_VSERVER_INFO - FEATURE vshelper || return 1
976 if test -n "$1"; then
978 appdir=$($_VSERVER_INFO "$1" APPDIR vshelper) || return 1
979 test ! -e "$appdir/debug" || return 0
985 function vshelper._getHandlerInternal
990 shift ## HACK: see below the note about the 'set -u' mode
992 while test "$#" -ge 2; do
997 test "$_vghi_mod" "$_vghi_obj" || continue
1000 eval $_vghi_var=\$_vghi_obj
1003 read _vghi_tmp <"$_vghi_obj"
1004 eval $_vghi_var=:\$_vghi_tmp
1006 (*) panic $"Internal error, unexpected modifier '$_vghi_mod'"
1014 ## Usage: vshelper.getHandler <result-var> <vserver> <action>
1015 function vshelper.getHandler
1018 _vgh_appdir=$($_VSERVER_INFO "$2" APPDIR vshelper) || _vgh_appdir=
1020 declare -a _vgh_search_list=( X )
1021 ## HACK: when we are in 'set -u' mode, empty lists are causing errors
1023 test -z "$_vgh_appdir" || _vgh_search_list=( "${_vgh_search_list[@]}" -x "$_vgh_appdir/$3" )
1024 test -z "$_vgh_appdir" || _vgh_search_list=( "${_vgh_search_list[@]}" -e "$_vgh_appdir/action" )
1025 _vgh_search_list=( "${_vgh_search_list[@]}" -x "$__CONFDIR"/.defaults/apps/vshelper/"$3" )
1026 _vgh_search_list=( "${_vgh_search_list[@]}" -e "$__CONFDIR"/.defaults/apps/vshelper/action )
1028 ! vshelper._getHandlerInternal "$1" "${_vgh_search_list[@]}" || return 0
1032 ## Usage: vshelper.init <vserver> [<method> <args>*]
1033 function vshelper.doInit
1035 vshelper.isEnabled || return 0
1038 xid=$($_VSERVER_INFO "$1" CONTEXT false) && test -n "$xid" || {
1039 warning $"vshelper.init: can not determine xid of vserver '$vserver'; returned value was '$xid'
1041 This usually means that you're using an init-less init-style, but the
1042 guest isn't configured to start any service. Try enabling a service,
1043 changing the init-style, or making the contexts persistent."
1047 local f="$__VSHELPERSTATEDIR/$xid"
1054 if test -n "$2"; then
1067 ## Usage: vshelper.doDestroy <vserver> <xid>
1068 function vshelper.doDestroy
1070 vshelper.isEnabled || return 0
1072 $_RM -f "$__VSHELPERSTATEDIR/$2"
1075 ## Usage: vshelper.initSync <vserver> <pipe-varname> [<method>]
1076 function vshelper.initSync
1079 _vis_tmpdir=$($_MKTEMPDIR vserver-stop.XXXXXX) || {
1080 warning $"Failed to generate temporary directory for vshelper sync"
1084 local _vis_fifo="$_vis_tmpdir"/pipe
1085 $_MKFIFO -m700 "$_vis_fifo"
1086 vshelper.doInit "$1" "${3:-sync}" "$_vis_fifo"
1090 ## Usage: vshelper.getSyncTimeout <vserver> <varname>
1091 function vshelper.getSyncTimeout
1093 local _vgst_appdir _vgst_file _vgst_tmp
1094 _vgst_appdir=$($_VSERVER_INFO "$1" APPDIR vshelper) || _vgst_appdir=
1096 findFile _vgst_file ${_vgst_appdir:+"$_vgst_appdir"/sync-timeout} "$__CONFDIR"/.defaults/apps/vshelper/sync-timeout ''
1097 test -n "$_vgst_file" || return 1
1098 read _vgst_tmp <"$_vgst_file"
1102 function vshelper.initStopSync
1104 local _iss_sync_dir=$($_MKTEMPDIR vshelper-stop-sync.XXXXXX) || {
1105 warning $"Failed to generate directory for vshelper sync"
1108 $_MKFIFO -m700 "$_iss_sync_dir/pipe"
1110 eval "$1"=\$_iss_sync_dir
1111 VSHELPER_STOP_SYNC="$_iss_sync_dir/pipe"
1112 export VSHELPER_STOP_SYNC
1115 function vshelper.waitForStopSync
1118 cat "$sync_dir/pipe" &> /dev/null
1122 function vshelper.doStopSync
1124 test ! -p "$VSHELPER_STOP_SYNC" || echo stopped > "$VSHELPER_STOP_SYNC"
1127 function vshelper.isStopSync
1129 test -p "$VSHELPER_STOP_SYNC" || return 1
1133 function _rpmFake.getCapFlags
1137 if test -n "$ctx" && ! $_VSERVER_INFO - FEATURE migrate; then
1138 set -- $($_CHCONTEXT_COMPAT --xid 1 \
1139 $_SH -c "$_CAT /proc/[0-9]*/status | $_EGREP '^(CapBset|s_context|ctxflags)'" | \
1140 $_GREP -B 1 -A 1 "^s_context: $ctx " | \
1141 $_SED -e '1,3p;d' | $_AWK '{ print $2 }')
1146 if test -n "$3"; then
1147 RPM_FAKE_CAP=$[ ~0x$1 ]
1150 RPM_FAKE_CAP=$[ ~0xd40c04ff ]
1155 function rpmFake.init
1159 vdir=$($_VSERVER_INFO "$1" VDIR) || vdir="$1"
1160 ctx=$($_VSERVER_INFO "$1" CONTEXT) || ctx=
1163 panic $"Can not find chroot environment at '$vdir' for '$1'"
1165 _rpmFake.getCapFlags "$ctx"
1167 RPM_FAKE_CHROOT=$vdir
1171 function rpmFake.exec
1173 export RPM_FAKE_CHROOT RPM_FAKE_CTX RPM_FAKE_CAP RPM_FAKE_FLAGS
1175 LD_PRELOAD=$_RPM_FAKE_SO${LD_PRELOAD:+:$LD_PRELOAD} \