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}
24 declare -r VS_ALLVSERVERS_ARGS=all,marked,unmarked,stopped,running
35 test -n "$_fo_i" || continue
36 test ! $_fo_mod "$_fo_i" || { _fo_file=$_fo_i; break; }
39 test -z "$_fo_i" -o -n "$_fo_file" || {
40 echo "Can not find file for '$_fo_var'; aborting"
44 eval "$_fo_var=\"$_fo_file\""
60 test ! -s "$dst" || return 0
66 test -n "$tmp" -a -s "$tmp" || return 0
67 $_CP -af "$tmp" "$dst"
70 ## Usage: isRegularFile <filename> [<mod>]
71 function isRegularFile
73 test ${2:--f} "$1" || return 1
76 (*.rpmsave|*.rpmnew|*.rpmorig|*.cfsaved*|*.~*~) return 1;;
82 function getPhysicalDir
84 ( set -P && cd "$1" && pwd )
87 ## Usage:: isDirectoryEmpty <dir> [<ignore-lost+found>]
88 function isDirectoryEmpty
92 shopt -s nullglob || *
95 test -z "$2" -o "$2" = 0 || ignore_lostfound=
100 test "$ignore_lostfound" || exit 1
102 (*) echo "$i"; exit 1
110 ## Usage: logging <message>
113 if test -n "$_VS_LOGFILE"; then
114 echo "$@" >>"$_VS_LOGFILE"
120 ## Usage: warning <message>
123 if test -n "$_VS_ERRFILE"; then
124 echo "$@" >>"$_VS_ERRFILE"
130 ## Usage: panic <message>
133 if test -n "$_VS_ERRFILE"; then
134 echo "$@" >>"$_VS_ERRFILE"
142 ## Usage: execute <message>
145 test -z "${DEBUG_EXEC:-}" || echo "$@"
146 test "${DEBUG_EXEC:-}" = noexec || exec "$@"
151 ## Usage: spawn <message>
154 test -z "${DEBUG_EXEC:-}" || echo "$@"
155 test "${DEBUG_EXEC:-}" = noexec || "$@"
158 ## Usage: isNumber <arg>
162 let tmp=$1+0 2>/dev/null || test -z "${1//0/}" -a -n "$1" || return 1
166 ## Usage: hasSubstring <haystack> <needle>+
167 function hasSubstring
175 test x"${pat/*$i*/$i}" = x"$i" || continue
182 ## Usage: colorize <style> <command>
192 findFile cfile "$__CONFDIR"/.defaults/styles/"$style" ''
193 if test -n "$cfile"; then
197 (bold) echo -ne "\e[1m";;
198 (emph) echo -ne "\e[34m";;
199 (info) echo -ne "\e[0;34m";;
200 (warn*) echo -ne "\e[1;31m";;
201 (error) echo -ne "\e[1;33;41m";;
213 if test -n "$_VS_ERRFILE"; then
214 echo "$@" >>"$_VS_ERRFILE"
216 colorize error echo -n "$@" >&2
225 colorize warning warning "$@"
230 colorize info echo "$@"
234 ## Usage: xtermTitle <title>
238 echo -ne "\e]0;$@\007"
242 ## Usage: lock <lockfile> [<timeout>]
245 local tmp=$($_MKTEMP vserver-lock.XXXXXX)
249 $_LOCKFILE "$1" $tmp $2 &
250 $_GREP -q true $tmp 2>/dev/null || return 1
252 _VS_LOCKS="$! $_VS_LOCKS"
255 ## Usage: unlock [<num>]
262 while test "$#" -gt 0; do
263 kill -HUP "$1" >/dev/null || :
265 test "$num" != 1 || break
266 test -z "$num" || let --num
271 function get_init_cwd
273 if test -n "$INIT_CWD"; then
279 function set_init_cwd
285 function _setVserverDir
289 ./*) VSERVER_DIR="`get_init_cwd`/$vserver";;
290 /*) VSERVER_DIR="$vserver" ;;
291 *) VSERVER_DIR="$__CONFDIR/$vserver" ;;
295 function _setVserverName
297 if test -e "$VSERVER_DIR"/name; then
298 read VSERVER_NAME <"$VSERVER_DIR"/name
300 VSERVER_NAME=$(basename "$VSERVER_DIR")
304 function _pkgMountBindDir()
306 test "$1" != "$2" || return 0
308 $_MOUNT -n --bind "$1" "$2"
311 function _pkgSetVarsBase
315 if test -d "$vserver/vdir"; then
317 VDIR=$(getPhysicalDir "$vserver/vdir")
319 PKGDIR=$BASEDIR/apps/pkgmgmt
320 test -d "$PKGDIR" || {
321 echo "Can not find configuration-directory for package-managment tools"
324 findDir EXECDIR $PKGDIR/execdir /
326 VDIR=$(getPhysicalDir "$vserver")
331 BASEDIR=$__CONFDIR/$vserver
332 test -d "$BASEDIR" || {
333 echo "Can not find configuration-directory"
338 test -d "$VDIR" || VDIR=$__DEFAULT_VSERVERDIR/$vserver
339 VDIR=$(getPhysicalDir "$VDIR")
341 PKGDIR=$BASEDIR/apps/pkgmgmt
342 test -d "$PKGDIR" || {
343 echo "Can not find configuration-directory for package-managment tools"
347 findDir EXECDIR $PKGDIR/execdir /
352 if test -z "$WORKAROUND_106057"; then
355 _rpmdb_mntpoint=/.rpmdb
359 function _pkgSetVarsRPM
361 if test -n "$PKGDIR"; then
362 findDir RPMETCDIR $PKGDIR/rpmetc $PKGDIR/base/rpm/etc /etc/rpm
363 findDir RPMSTATEDIR $PKGDIR/rpmstate $PKGDIR/base/rpm/state
365 findDir RPMLIBDIR $PKGDIR/rpmlib /
368 findDir RPMETCDIR "$VDIR"/etc/rpm /etc/rpm
369 findDir RPMSTATEDIR "$VDIR"/var/lib/rpm
373 RPMSTATEDIR=$(getPhysicalDir "$RPMSTATEDIR")
374 RPMETCDIR=$(getPhysicalDir "$RPMETCDIR")
377 function _pkgSetVarsApt
379 if test -n "$PKGDIR"; then
380 findDir APTETCDIR $PKGDIR/aptetc $PKGDIR/base/apt/etc /etc/apt
381 findDir APTSTATEDIR $PKGDIR/aptstate $PKGDIR/base/apt/state
382 findDir APTCACHEDIR $PKGDIR/aptcache $PKGDIR/base/apt/cache
383 findDir APTARCHIVDIR $PKGDIR/aptarchives $PKGDIR/base/apt/archives /var/cache/apt/archives
385 findDir APTETCDIR "$VDIR"/etc/apt /etc/apt
386 findDir APTSTATEDIR "$VDIR"/var/state/apt
387 findDir APTCACHEDIR "$VDIR"/var/cache/apt
388 findDir APTARCHIVDIR "$VDIR"/var/cache/apt/archives /var/cache/apt/archives
391 findFile APT_CONFIG "$APTETCDIR"/apt.conf ""
392 test -z "$APT_CONFIG" || export APT_CONFIG
395 function _pkgSetVarsYum
397 if test -n "$PKGDIR"; then
398 findDir YUMETCDIR $PKGDIR/yumetc $PKGDIR/base/yum/etc /etc
399 findDir YUMCACHEDIR $PKGDIR/yumcache $PKGDIR/base/yum/cache
401 findDir YUMETCDIR "$VDIR"/etc /etc
402 findDir YUMCACHEDIR "$VDIR"/var/cache/yum
407 function _pkgMountBase
412 function _pkgMountApt
417 function _pkgMountYum
422 function _pkgMountRPM
424 _pkgMountBindDir "$RPMETCDIR" /etc/rpm
425 test "$RPMLIBDIR" = "/" || _pkgMountBindDir "$RPMLIBDIR" /usr/lib/rpm
427 pushd "$VDIR" >/dev/null
429 $_SECURE_MOUNT --chroot -n --bind "$RPMSTATEDIR" "$_rpmdb_mntpoint"
430 test -z "$WORKAROUND_106057" || mount -n --bind "$RPMSTATEDIR" "$_rpmdb_mntpoint"
432 test -e "$VDIR"/proc/self/status || \
433 $_SECURE_MOUNT --chroot -n -t proc none /proc
438 function _pkgSetEnvBase
440 test "$EXECDIR" = "/" || {
442 LD_LIBRARY_PATH=$EXECDIR${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
445 export PATH LD_LIBRARY_PATH
448 function _pkgSetEnvApt
453 function _pkgSetEnvYum
458 function _pkgSetEnvRPM
461 RPM_FAKE_NAMESPACE_MOUNTS=$_rpmdb_mntpoint
462 RPM_BINARY=$_VRPM_PRELOAD
464 export CUR_VSERVER RPM_FAKE_NAMESPACE_MOUNTS RPM_BINARY
476 rpm) _pkgSetVarsRPM;;
477 apt) _pkgSetVarsApt;;
478 yum) _pkgSetVarsYum;;
479 *) echo "Unknown packaging flavor" >&2; exit 1;;
502 _PKG_VSERVER=$vserver
505 function isAvoidNamespace
509 $_VSERVER_INFO - FEATURE namespace || return 0
510 cfgdir=$($_VSERVER_INFO "$1" CFGDIR) || return 0
511 test ! -e "$cfgdir"/namespace || return 1
512 test -e "$__CONFDIR"/.defaults/nonamespace -o \
513 -e "$cfgdir"/nonamespace
516 function isNamespaceCleanup
520 $_VSERVER_INFO - FEATURE namespace || return 1
521 cfgdir=$($_VSERVER_INFO "$1" CFGDIR) || return 1
522 isAvoidNamespace "$1" && return 1
523 test -e "$cfgdir"/namespace-cleanup && return 0
524 test -e "$cfgdir"/nonamespace-cleanup -o \
525 -e "$__CONFDIR"/.defaults/nonamespace-cleanup && return 1
529 ## Usage: getAllVservers <var> [<KIND>*]
530 function getAllVservers
533 declare -a _ga_tmp=()
535 for _ga_i in $__CONFDIR/*; do
536 isRegularFile "$_ga_i" -d || continue
538 test ! -e "$_ga_i"/disabled || continue
539 test -d "$_ga_i"/vdir || continue
542 local _ga_markfile=$_ga_i/apps/init/mark
545 (MARKED) test -s "$_ga_markfile" || _ga_doadd=;;
546 (UNMARKED) test ! -s "$_ga_markfile" || _ga_doadd=;;
547 (STOPPED) ! $_VSERVER "$_ga_i" running &>/dev/null || _ga_doadd=;;
548 (RUNNING) $_VSERVER "$_ga_i" running &>/dev/null || _ga_doadd=;;
550 (*) panic $"Unknown vserver tagging '$2'";;
553 test -z "$_ga_doadd" || _ga_tmp=( "${_ga_tmp[@]}" "${_ga_i##$__CONFDIR/}")
556 eval $1='( "${_ga_tmp[@]}" )'
559 ## Usage: getAllVserversByArg <var> <arg>
560 function getAllVserversByArg
565 (--all) _gav_mark=ALL;;
566 (--marked) _gav_mark=MARKED;;
567 (--unmarked) _gav_mark=UNMARKED;;
568 (--stopped) _gav_mark=STOPPED;;
569 (--running) _gav_mark=RUNNING;;
573 getAllVservers "$1" "$_gav_mark"
576 ## Usage: _getProcNumberCount <ctx> <var>
577 function _getProcNumberCount
580 local _gp_procnr_cnt=0
582 # Use /proc/virtual from kernel 2.6 when possible
583 if test -d "/proc/virtual"; then
584 set -- $($_GREP '^Tasks:' "/proc/virtual/$1/status" 2>/dev/null)
587 _gp_procnr_cnt=$($_VPS ax | $_AWK '{print $2}' | $_GREP -x "$1" | $_WC -l )
590 let _gp_procnr_cnt=_gp_procnr_cnt+0
591 eval $_gp_var=\$_gp_procnr_cnt
594 ## Usage: getVserverCtx <vdir> <result-varname> [<procnumber-varname> [<do-cleanup>]]
595 ## Returns: 0 iff vserver is running
596 function getVserverStatus
598 test -r "$1"/run || return 1
601 read _gvs_ctx <"$1"/run
604 if test "$1" = "$($_VUNAME -g --xid "$_gvs_ctx" context)"; then
605 test -n "$3" || return 0
607 _getProcNumberCount "$_gvs_ctx" _gvs_tmp
610 test -n "$3" || return 1
615 if test "$_gvs_tmp" = 0; then
616 local runfile=$($_READLINK "$1/run")
617 test -z "$4" || $_RM -f "$runfile"
624 ## Usage: isCtxRunning <ctx>
625 function isCtxRunning
628 _getProcNumberCount "$1" _tmp
632 ## Usage: isVserverRunning <vdir> [<ctx-varname>]
633 function isVserverRunning
635 local _ivr_ctx _ivr_procnum
637 getVserverStatus "$1" _ivr_ctx _ivr_procnum 1 || return 1
638 test "$_ivr_procnum" != 0 || return 1
639 test -z "$2" || eval "$2"=\$_ivr_ctx
643 ## Called as 'getFileValue <varname> <filename>+'
644 function getFileValue
650 findFile _gfv_file "$@" ''
651 test -n "$_gfv_file" -a -r "$_gfv_file" || return 0
652 eval read "$_gfv_var" <"$_gfv_file"
655 ## Called as 'getFileArray <varname> <filename>+'
656 function getFileArray
662 findFile _gfa_file "$@" ''
663 test -n "$_gfa_file" -a -r "$_gfa_file" || return 0
664 local IFS=$_VS_NEWLINE
665 eval "$_gfa_var"='( $(< "$_gfa_file") )'
668 function checkComponents
679 (core) test -x "$_CHBIND" || failed=1;;
680 (build) test -x "$_VSERVER_BUILD" || failed=1;;
681 (sysv) test -x "$__INITRDDIR/vserver" || failed=1;;
682 (devel) test -d "$__INCLUDEDIR/vserver.h" || failed=1;;
683 (*) echo "Unknown component '$i'" >&2
688 test -z "$failed" || {
697 ## Usage: isKernelAPI <ver> [<cmp-modifier>]
701 api=$($_VSERVER_INFO - APIVER) || api=0
702 test $[ $api ] -${2:-ge} $[ $1 ]
705 ## Usage: callInNamespace <vserver> <command> <args>*
706 function callInNamespace
710 isAvoidNamespace "$1" || \
711 ctx=$( $_VSERVER_INFO "$1" CONTEXT f ) || ctx=
714 if test -n "$ctx"; then
715 $_VNAMESPACE --enter "$ctx" -- "$@"
721 ## Usage: setDefaultTTY <vdir> [<fallback-tty>]
722 function setDefaultTTY
726 cfgdir=$($_VSERVER_INFO "$1" APPDIR init) || cfgdir=
727 findObject -e ttyname \
728 ${cfgdir:+"$cfgdir"/tty} \
729 "$__CONFDIR/.defaults/apps/init/tty" \
732 if test -f "$ttyname"; then
740 ## Usage: killContext <XID> [<SIG>]
745 #$_VKILL -s STOP --xid "$1" 1 &>/dev/null || :
746 $_VKILL -s "$sig" --xid "$1" 1 &>/dev/null || :
747 $_VKILL -s "$sig" --xid "$1" &>/dev/null || :
748 #$_VKILL -s "$sig" --xid "$1" 1 &>/dev/null || :
749 #$_VKILL -s CONT --xid "$1" 1 &>/dev/null || :
754 test ! -e "$__CONFDIR/.defaults/apps/vlogin/disable"
757 ## Usage: pkgmgmt.guessStyle <vserver> <resultvar>
758 function pkgmgmt.guessStyle()
761 _pgs_vdir=$($_VSERVER_INFO "$1" VDIR) || {
762 echo $"Can not determine vserver-root" >&2
765 local _pgs_cfgdir=$($_VSERVER_INFO "$1" APPDIR pkgmgmt) || :
767 if test -n "$_pgs_cfgdir" -a -e "$_pgs_cfgdir"/style; then
768 read style <"$_pgs_cfgdir"/style
769 elif test -e "$_pgs_vdir"/etc/redhat-release -o -e "$_pgs_vdir"/etc/fedora-release; then
771 elif test -e "$_pgs_vdir"/etc/mandrake-release; then
773 elif test -e "$_pgs_vdir"/etc/debian_version; then
775 elif test -e "$_pgs_vdir"/etc/SuSE-release; then
778 echo $"Can not determine packagemanagement style" >&2
786 ## Usage: pkgmgmt.isInternal <vserver>
787 ## returns true iff <vserver> is configured for internal packagemanagement
788 ## A typical application is
790 ## | pkgmgmt.isInternal "$vserver" || is_external=1
791 function pkgmgmt.isInternal
793 local cfgdir=$($_VSERVER_INFO "$1" APPDIR pkgmgmt) || :
795 test -z "$cfgdir" -o ! -d "$cfgdir" -o -e "$cfgdir"/internal
798 ## Usage: pkgmgmt.isAptAvailable <cfgdir> <vdir> [<is-internal>]
799 function pkgmgmt.isAptAvailable
803 local is_internal="$3"
806 if test -n "$is_internal"; then
808 test -d "$cfgdir"/base/apt -o -d "$cfgdir"/aptetc || have_apt=
811 for i in /bin /usr/bin /usr/local/bin; do
812 test ! -x "$vdir$i"/apt-get || { have_apt=1; break; }
816 test -n "$have_apt" && return 0 || return 1
819 ## Usage: pkgmgmt.isYumAvailable <cfgdir> <vdir> [<is-internal>]
820 function pkgmgmt.isYumAvailable
824 local is_internal="$3"
827 if test -n "$is_internal"; then
829 test -d "$cfgdir"/base/yum -o -d "$cfgdir"/yumetc || have_yum=
832 for i in /bin /usr/bin /usr/local/bin; do
833 test ! -x "$vdir$i"/yum || { have_yum=1; break; }
837 test -n "$have_yum" && return 0 || return 1
841 function vshelper.doSanityCheck
843 local vshelper this_xid i
844 declare -a warnings=()
845 local solution_disable=
846 local solution_sysctl=
848 vshelper.isEnabled && vshelper.isEnabled warning || return 0
850 this_xid=$($_VSERVER_INFO - XID) ||
851 panic $"Failed to determine current context; aborting..."
853 ## Do nothing in other xid's; the helper will be executed in xid 0 only
854 test "$this_xid" = 0 || return 0
856 local proc_file=/proc/sys/kernel/vshelper
858 if ! test -r "$proc_file"; then
860 warnings=( "${warnings[@]}"
861 $"File '$proc_file' does not exist but is required for vshelper setup" )
864 vshelper=$(cat "$proc_file")
866 $_CMP -s "$vshelper" "$_VSHELPER" || {
868 test -r "$vshelper" && readable=1
869 warnings=( "${warnings[@]}"
870 $"The configured vshelper '$vshelper' does not match the 'vshelper'
871 script of the util-vserver package.${readable:+ Maybe you have two versions installed?}"
878 test -d "$__VSHELPERSTATEDIR" || {
879 warnings=( "${warnings[@]}"
881 The vshelper state-directory '$__VSHELPERSTATEDIR' does not exist; since
882 it is created by 'make install', this indicates a serious problem with
883 your util-vserver installation" )
887 test "${#warnings[@]}" -eq 0 || {
889 The following problem(s) were encountered while verifying vshelper
892 for i in "${warnings[@]}"; do
898 To fix this, you can:"
900 test -z "$solution_disable" || warning $"\
901 * disable vshelper entirely by executing
902 | touch \"$__CONFDIR/.defaults/apps/vshelper/disabled\"
903 * disable only this message by executing
904 | touch \"$__CONFDIR/.defaults/apps/vshelper/warning-disabled\""
906 test -x "$solution_sysctl" || warning $"\
907 * configure the util-vserver vshelper script, e.g. by adding
908 | kernel.vshelper = $_VSHELPER
909 to /etc/sysctl.conf and rebooting the machine, or by executing
910 | echo \"$_VSHELPER\" >$proc_file"
920 ## Usage: vshelper.isEnabled [<style>] [<vserver>]
921 function vshelper.isEnabled
923 local f=${1:+$1-}disabled
924 test ! -e "$__CONFDIR"/.defaults/apps/vshelper/"$f" || return 1
925 $_VSERVER_INFO - FEATURE vshelper || return 1
926 if test -n "$2"; then
928 appdir=$($_VSERVER_INFO "$2" APPDIR vshelper) || return 0
929 test -z "$2" -o ! -e "$appdir/$f" || return 1
935 ## Usage: vshelper.isDebug [<vserver>]
936 function vshelper.isDebug
938 test ! -e "$__CONFDIR"/.defaults/apps/vshelper/debug || return 0
939 $_VSERVER_INFO - FEATURE vshelper || return 1
940 if test -n "$1"; then
942 appdir=$($_VSERVER_INFO "$1" APPDIR vshelper) || return 1
943 test ! -e "$appdir/debug" || return 0
949 function vshelper._getHandlerInternal
954 shift ## HACK: see below the note about the 'set -u' mode
956 while test "$#" -ge 2; do
961 test "$_vghi_mod" "$_vghi_obj" || continue
964 eval $_vghi_var=\$_vghi_obj
967 read _vghi_tmp <"$_vghi_obj"
968 eval $_vghi_var=:\$_vghi_tmp
970 (*) panic $"Internal error, unexpected modifier '$_vghi_mod'"
978 ## Usage: vshelper.getHandler <result-var> <vserver> <action>
979 function vshelper.getHandler
982 _vgh_appdir=$($_VSERVER_INFO "$2" APPDIR vshelper) || _vgh_appdir=
984 declare -a _vgh_search_list=( X )
985 ## HACK: when we are in 'set -u' mode, empty lists are causing errors
987 test -z "$_vgh_appdir" || _vgh_search_list=( "${_vgh_search_list[@]}" -x "$_vgh_appdir/$3" )
988 test -z "$_vgh_appdir" || _vgh_search_list=( "${_vgh_search_list[@]}" -e "$_vgh_appdir/action" )
989 _vgh_search_list=( "${_vgh_search_list[@]}" -x "$__CONFDIR"/.defaults/apps/vshelper/"$3" )
990 _vgh_search_list=( "${_vgh_search_list[@]}" -e "$__CONFDIR"/.defaults/apps/vshelper/action )
992 ! vshelper._getHandlerInternal "$1" "${_vgh_search_list[@]}" || return 0
996 ## Usage: vshelper.init <vserver> [<method> <args>*]
997 function vshelper.doInit
999 vshelper.isEnabled || return 0
1002 xid=$($_VSERVER_INFO "$1" CONTEXT false) && test -n "$xid" || {
1003 warning $"vshelper.init: can not determine xid of vserver '$vserver'; returned value was '$xid'
1005 This usually means that you're using an init-less init-style, but the
1006 guest isn't configured to start any service. Try enabling a service,
1007 changing the init-style, or making the contexts persistent."
1011 local f="$__VSHELPERSTATEDIR/$xid"
1018 if test -n "$2"; then
1031 ## Usage: vshelper.doDestroy <vserver> <xid>
1032 function vshelper.doDestroy
1034 vshelper.isEnabled || return 0
1036 $_RM -f "$__VSHELPERSTATEDIR/$2"
1039 ## Usage: vshelper.initSync <vserver> <pipe-varname> [<method>]
1040 function vshelper.initSync
1043 _vis_tmpdir=$($_MKTEMPDIR vserver-stop.XXXXXX) || {
1044 warning $"Failed to generate temporary directory for vshelper sync"
1048 local _vis_fifo="$_vis_tmpdir"/pipe
1049 $_MKFIFO -m700 "$_vis_fifo"
1050 vshelper.doInit "$1" "${3:-sync}" "$_vis_fifo"
1054 ## Usage: vshelper.getSyncTimeout <vserver> <varname>
1055 function vshelper.getSyncTimeout
1057 local _vgst_appdir _vgst_file _vgst_tmp
1058 _vgst_appdir=$($_VSERVER_INFO "$1" APPDIR vshelper) || _vgst_appdir=
1060 findFile _vgst_file ${_vgst_appdir:+"$_vgst_appdir"/sync-timeout} "$__CONFDIR"/.defaults/apps/vshelper/sync-timeout ''
1061 test -n "$_vgst_file" || return 1
1062 read _vgst_tmp <"$_vgst_file"
1066 function vshelper.initStopSync
1068 local _iss_sync_dir=$($_MKTEMPDIR vshelper-stop-sync.XXXXXX) || {
1069 warning $"Failed to generate directory for vshelper sync"
1072 $_MKFIFO -m700 "$_iss_sync_dir/pipe"
1074 eval "$1"=\$_iss_sync_dir
1075 VSHELPER_STOP_SYNC="$_iss_sync_dir/pipe"
1076 export VSHELPER_STOP_SYNC
1079 function vshelper.waitForStopSync
1082 cat "$sync_dir/pipe" &> /dev/null
1086 function vshelper.doStopSync
1088 test ! -p "$VSHELPER_STOP_SYNC" || echo stopped > "$VSHELPER_STOP_SYNC"
1091 function vshelper.isStopSync
1093 test -p "$VSHELPER_STOP_SYNC" || return 1
1097 function _rpmFake.getCapFlags
1101 if test -n "$ctx" && ! $_VSERVER_INFO - FEATURE migrate; then
1102 set -- $($_CHCONTEXT_COMPAT --xid 1 \
1103 $_SH -c "$_CAT /proc/[0-9]*/status | $_EGREP '^(CapBset|s_context|ctxflags)'" | \
1104 $_GREP -B 1 -A 1 "^s_context: $ctx " | \
1105 $_SED -e '1,3p;d' | $_AWK '{ print $2 }')
1110 if test -n "$3"; then
1111 RPM_FAKE_CAP=$[ ~0x$1 ]
1114 RPM_FAKE_CAP=$[ ~0xd40c04ff ]
1119 function rpmFake.init
1123 vdir=$($_VSERVER_INFO "$1" VDIR) || vdir="$1"
1124 ctx=$($_VSERVER_INFO "$1" CONTEXT) || ctx=
1127 panic $"Can not find chroot environment at '$vdir' for '$1'"
1129 _rpmFake.getCapFlags "$ctx"
1131 RPM_FAKE_CHROOT=$vdir
1135 function rpmFake.exec
1137 export RPM_FAKE_CHROOT RPM_FAKE_CTX RPM_FAKE_CAP RPM_FAKE_FLAGS
1139 LD_PRELOAD=$_RPM_FAKE_SO${LD_PRELOAD:+:$LD_PRELOAD} \