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 \
358 $PKGDIR/base/etc/rpm /etc/rpm
359 findDir RPMSTATEDIR $PKGDIR/rpmstate $PKGDIR/base/rpm/state \
360 $PKGDIR/base/var/lib/rpm
362 findDir RPMLIBDIR $PKGDIR/rpmlib /
365 findDir RPMETCDIR "$VDIR"/etc/rpm /etc/rpm
366 findDir RPMSTATEDIR "$VDIR"/var/lib/rpm
370 RPMSTATEDIR=$(getPhysicalDir "$RPMSTATEDIR")
371 RPMETCDIR=$(getPhysicalDir "$RPMETCDIR")
374 function _pkgSetVarsApt
376 if test -n "$PKGDIR"; then
377 findDir APTETCDIR $PKGDIR/aptetc $PKGDIR/base/apt/etc /etc/apt
378 findDir APTSTATEDIR $PKGDIR/aptstate $PKGDIR/base/apt/state
379 findDir APTCACHEDIR $PKGDIR/aptcache $PKGDIR/base/apt/cache
380 findDir APTARCHIVDIR $PKGDIR/aptarchives $PKGDIR/base/apt/archives /var/cache/apt/archives
382 findDir APTETCDIR "$VDIR"/etc/apt /etc/apt
383 findDir APTSTATEDIR "$VDIR"/var/state/apt
384 findDir APTCACHEDIR "$VDIR"/var/cache/apt
385 findDir APTARCHIVDIR "$VDIR"/var/cache/apt/archives /var/cache/apt/archives
388 findFile APT_CONFIG "$APTETCDIR"/apt.conf ""
389 test -z "$APT_CONFIG" || export APT_CONFIG
392 function _pkgSetVarsYum
394 if test -n "$PKGDIR"; then
395 findDir YUMETCDIR $PKGDIR/yumetc $PKGDIR/base/yum/etc /etc
396 findDir YUMCACHEDIR $PKGDIR/yumcache $PKGDIR/base/yum/cache
398 findDir YUMETCDIR "$VDIR"/etc /etc
399 findDir YUMCACHEDIR "$VDIR"/var/cache/yum
403 function _pkgSetVarsUrpmi
405 if test -n "$PKGDIR"; then
406 findDir URPMIETCDIR $PKGDIR/urpmietc $PKGDIR/base/etc/urpmi /etc/urpmi
407 findDir URPMISTATEDIR $PKGDIR/urpmistate $PKGDIR/base/var/lib/urpmi
409 findDir URPMIETCDIR "$VDIR"/etc/urpmi /etc/urpmi
410 findDir URPMISTATEDIR "$VDIR"/var/lib/urpmi /var/lib/urpmi
415 function _pkgMountBase
420 function _pkgMountApt
425 function _pkgMountYum
430 function _pkgMountUrpmi
432 _pkgMountBindDir "$RPMSTATEDIR" "$URPMISTATEDIR/../../../.rpmdb"
435 function _pkgMountRPM
437 _pkgMountBindDir "$RPMETCDIR" /etc/rpm
438 test "$RPMLIBDIR" = "/" || _pkgMountBindDir "$RPMLIBDIR" /usr/lib/rpm
440 pushd "$VDIR" >/dev/null
442 $_SECURE_MOUNT --chroot -n --bind "$RPMSTATEDIR" "$_rpmdb_mntpoint"
443 test -z "$WORKAROUND_106057" || mount -n --bind "$RPMSTATEDIR" "$_rpmdb_mntpoint"
445 test -e "$VDIR"/proc/self/status || \
446 $_SECURE_MOUNT --chroot -n -t proc none /proc
451 function _pkgSetEnvBase
453 test "$EXECDIR" = "/" || {
455 LD_LIBRARY_PATH=$EXECDIR${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
458 export PATH LD_LIBRARY_PATH
461 function _pkgSetEnvApt
466 function _pkgSetEnvYum
471 function _pkgSetEnvUrpmi
476 function _pkgSetEnvRPM
479 RPM_FAKE_NAMESPACE_MOUNTS=$_rpmdb_mntpoint
480 RPM_BINARY=$_VRPM_PRELOAD
482 export CUR_VSERVER RPM_FAKE_NAMESPACE_MOUNTS RPM_BINARY
494 rpm) _pkgSetVarsRPM;;
495 apt) _pkgSetVarsApt;;
496 yum) _pkgSetVarsYum;;
497 urpmi) _pkgSetVarsUrpmi;;
498 *) echo "Unknown packaging flavor" >&2; exit 1;;
508 urpmi) _pkgMountUrpmi;;
518 urpmi) _pkgSetEnvUrpmi;;
523 _PKG_VSERVER=$vserver
526 function isAvoidNamespace
530 $_VSERVER_INFO - FEATURE namespace || return 0
531 cfgdir=$($_VSERVER_INFO "$1" CFGDIR) || return 0
532 test ! -e "$cfgdir"/namespace || return 1
533 test -e "$__CONFDIR"/.defaults/nonamespace -o \
534 -e "$cfgdir"/nonamespace
537 function isNamespaceCleanup
541 $_VSERVER_INFO - FEATURE namespace || return 1
542 cfgdir=$($_VSERVER_INFO "$1" CFGDIR) || return 1
543 isAvoidNamespace "$1" && return 1
544 test -e "$cfgdir"/namespace-cleanup && return 0
545 test -e "$cfgdir"/nonamespace-cleanup -o \
546 -e "$__CONFDIR"/.defaults/nonamespace-cleanup && return 1
550 ## Usage: getAllVservers <var> [<KIND>*]
551 function getAllVservers
554 declare -a _ga_tmp=()
557 local -a _ga_marks=( $3 )
560 for _ga_i in $__CONFDIR/*; do
561 isRegularFile "$_ga_i" -d || continue
563 test ! -e "$_ga_i"/disabled || continue
564 test -d "$_ga_i"/vdir || continue
567 local _ga_markfile=$_ga_i/apps/init/mark
570 (MARKED) test -s "$_ga_markfile" || _ga_doadd=;;
571 (UNMARKED) test ! -s "$_ga_markfile" || _ga_doadd=;;
572 (STOPPED) ! $_VSERVER "$_ga_i" running &>/dev/null || _ga_doadd=;;
573 (RUNNING) $_VSERVER "$_ga_i" running &>/dev/null || _ga_doadd=;;
578 local _ga_invert=false
579 for _ga_j in "${_ga_marks[@]}"; do
580 _ga_mark="$(echo "$_ga_j" | $_SED 's/^[!~]//')"
581 test "$_ga_j" = "$_ga_mark" || _ga_invert=true
582 test -s "$_ga_markfile" && $_GREP -qx "$_ga_mark" "$_ga_markfile" && \
585 test $_ga_f = $_ga_invert && \
588 (*) panic $"Unknown vserver tagging '$2'";;
591 test -z "$_ga_doadd" || _ga_tmp=( "${_ga_tmp[@]}" "${_ga_i##$__CONFDIR/}")
594 eval $1='( "${_ga_tmp[@]}" )'
597 declare -r VS_ALLVSERVERS_ARGS=all,marked,unmarked,stopped,running,mark:
598 ## Usage: getAllVserversByArg <var> <arg>
599 function getAllVserversByArg
607 while test "$#" -ge 1; do
612 (--all) _gav_mark=ALL;;
613 (--marked) _gav_mark=MARKED;;
614 (--unmarked) _gav_mark=UNMARKED;;
615 (--stopped) _gav_mark=STOPPED;;
616 (--running) _gav_mark=RUNNING;;
617 (--mark*) _gav_mark=MARK
618 _gav_extra=${_gav_i##*=}
619 test -n "$_gav_extra" -a "$_gav_extra" != "--mark" || \
624 (*) set -- "$_gav_v" "$@"
628 getAllVservers _gav_tmp "$_gav_mark" $_gav_extra
629 if test -n "$_gav_first"; then
630 _gav_res=( "${_gav_tmp[@]}" )
633 local _gav_n="${#_gav_res[@]}"
634 while test $_gav_i -lt $_gav_n; do
636 for _gav_j in "${_gav_tmp[@]}"; do
637 if test "$_gav_j" = "${_gav_res[$_gav_i]}"; then
642 if test "$_gav_found" = 0; then
643 unset _gav_res[$_gav_i]
647 _gav_res=( "${_gav_res[@]}" )
652 eval $_gav_v='( "${_gav_res[@]}" )'
655 ## Usage: _getProcNumberCount <ctx> <var>
656 function _getProcNumberCount
659 local _gp_procnr_cnt=0
661 # Use /proc/virtual from kernel 2.6 when possible
662 if test -d "/proc/virtual"; then
663 set -- $($_GREP '^Tasks:' "/proc/virtual/$1/status" 2>/dev/null)
666 _gp_procnr_cnt=$($_VPS ax | $_AWK '{print $2}' | $_GREP -x "$1" | $_WC -l )
669 let _gp_procnr_cnt=_gp_procnr_cnt+0
670 eval $_gp_var=\$_gp_procnr_cnt
673 ## Usage: getVserverCtx <vdir> <result-varname> [<procnumber-varname> [<do-cleanup>]]
674 ## Returns: 0 iff vserver is running
675 function getVserverStatus
677 test -r "$1"/run || return 1
680 read _gvs_ctx <"$1"/run
683 if test "$1" = "$($_VUNAME -g --xid "$_gvs_ctx" context)"; then
684 test -n "$3" || return 0
686 _getProcNumberCount "$_gvs_ctx" _gvs_tmp
689 test -n "$3" || return 1
694 if test "$_gvs_tmp" = 0; then
695 local runfile=$($_READLINK "$1/run")
696 test -z "$4" || $_RM -f "$runfile"
703 ## Usage: isCtxRunning <ctx>
704 function isCtxRunning
707 _getProcNumberCount "$1" _tmp
711 ## Usage: isVserverRunning <vdir> [<ctx-varname>]
712 function isVserverRunning
714 local _ivr_ctx _ivr_procnum
716 getVserverStatus "$1" _ivr_ctx _ivr_procnum 1 || return 1
717 test "$_ivr_procnum" != 0 || return 1
718 test -z "$2" || eval "$2"=\$_ivr_ctx
722 ## Called as 'getFileValue <varname> <filename>+'
723 function getFileValue
729 findFile _gfv_file "$@" ''
730 test -n "$_gfv_file" -a -r "$_gfv_file" || return 0
731 eval read "$_gfv_var" <"$_gfv_file"
734 ## Called as 'getFileArray <varname> <filename>+'
735 function getFileArray
741 findFile _gfa_file "$@" ''
742 test -n "$_gfa_file" -a -r "$_gfa_file" || return 0
743 local IFS=$_VS_NEWLINE
744 eval "$_gfa_var"='( $(< "$_gfa_file") )'
747 function checkComponents
758 (core) test -x "$_CHBIND" || failed=1;;
759 (build) test -x "$_VSERVER_BUILD" || failed=1;;
760 (sysv) test -x "$__INITRDDIR/vserver" || failed=1;;
761 (devel) test -d "$__INCLUDEDIR/vserver.h" || failed=1;;
762 (*) echo "Unknown component '$i'" >&2
767 test -z "$failed" || {
776 ## Usage: isKernelAPI <ver> [<cmp-modifier>]
780 api=$($_VSERVER_INFO - APIVER) || api=0
781 test $[ $api ] -${2:-ge} $[ $1 ]
784 ## Usage: callInNamespace <vserver> <command> <args>*
785 function callInNamespace
789 isAvoidNamespace "$1" || \
790 ctx=$( $_VSERVER_INFO "$1" CONTEXT f ) || ctx=
793 if test -n "$ctx"; then
794 $_VNAMESPACE --enter "$ctx" -- "$@"
800 ## Usage: setDefaultTTY <vdir> [<fallback-tty>]
801 function setDefaultTTY
805 cfgdir=$($_VSERVER_INFO "$1" APPDIR init) || cfgdir=
806 findObject -e ttyname \
807 ${cfgdir:+"$cfgdir"/tty} \
808 "$__CONFDIR/.defaults/apps/init/tty" \
811 if test -f "$ttyname"; then
819 ## Usage: killContext <XID> [<SIG>]
824 #$_VKILL -s STOP --xid "$1" 1 &>/dev/null || :
825 $_VKILL -s "$sig" --xid "$1" 1 &>/dev/null || :
826 $_VKILL -s "$sig" --xid "$1" &>/dev/null || :
827 #$_VKILL -s "$sig" --xid "$1" 1 &>/dev/null || :
828 #$_VKILL -s CONT --xid "$1" 1 &>/dev/null || :
833 test ! -e "$__CONFDIR/.defaults/apps/vlogin/disable"
836 ## Usage: pkgmgmt.guessStyle <vserver> <resultvar>
837 function pkgmgmt.guessStyle()
840 _pgs_vdir=$($_VSERVER_INFO "$1" VDIR) || {
841 echo $"Can not determine vserver-root" >&2
844 local _pgs_cfgdir=$($_VSERVER_INFO "$1" APPDIR pkgmgmt) || :
846 if test -n "$_pgs_cfgdir" -a -e "$_pgs_cfgdir"/style; then
847 read style <"$_pgs_cfgdir"/style
848 elif test -e "$_pgs_vdir"/etc/redhat-release -o -e "$_pgs_vdir"/etc/fedora-release; then
850 elif test -e "$_pgs_vdir"/etc/mandrake-release; then
852 elif test -e "$_pgs_vdir"/etc/debian_version; then
854 elif test -e "$_pgs_vdir"/etc/SuSE-release; then
857 echo $"Can not determine packagemanagement style" >&2
865 ## Usage: pkgmgmt.isInternal <vserver>
866 ## returns true iff <vserver> is configured for internal packagemanagement
867 ## A typical application is
869 ## | pkgmgmt.isInternal "$vserver" || is_external=1
870 function pkgmgmt.isInternal
872 local cfgdir=$($_VSERVER_INFO "$1" APPDIR pkgmgmt) || :
874 test -z "$cfgdir" -o ! -d "$cfgdir" -o -e "$cfgdir"/internal
877 ## Usage: pkgmgmt.isAptAvailable <cfgdir> <vdir> [<is-internal>]
878 function pkgmgmt.isAptAvailable
882 local is_internal="$3"
885 if test -n "$is_internal"; then
887 test -d "$cfgdir"/base/apt -o -d "$cfgdir"/aptetc || have_apt=
890 for i in /bin /usr/bin /usr/local/bin; do
891 test ! -x "$vdir$i"/apt-get || { have_apt=1; break; }
895 test -n "$have_apt" && return 0 || return 1
898 ## Usage: pkgmgmt.isYumAvailable <cfgdir> <vdir> [<is-internal>]
899 function pkgmgmt.isYumAvailable
903 local is_internal="$3"
906 if test -n "$is_internal"; then
908 test -d "$cfgdir"/base/yum -o -d "$cfgdir"/yumetc || have_yum=
911 for i in /bin /usr/bin /usr/local/bin; do
912 test ! -x "$vdir$i"/yum || { have_yum=1; break; }
916 test -n "$have_yum" && return 0 || return 1
919 ## Usage: pkgmgmt.isUrpmiAvailable <cfgdir> <vdir> [<is-internal>]
920 function pkgmgmt.isUrpmiAvailable
924 local is_internal="$3"
927 if test -n "$is_internal"; then
929 test -d "$cfgdir"/base/var/lib/urpmi || have_urpmi=
932 for i in /bin /usr/bin /usr/local/bin; do
933 test ! -x "$vdir$i"/urpmi || { have_urpmi=1; break; }
937 test -n "$have_urpmi" && return 0 || return 1
941 function vshelper.doSanityCheck
943 local vshelper this_xid i
944 declare -a warnings=()
945 local solution_disable=
946 local solution_sysctl=
948 vshelper.isEnabled && vshelper.isEnabled warning || return 0
950 this_xid=$($_VSERVER_INFO - XID) ||
951 panic $"Failed to determine current context; aborting..."
953 ## Do nothing in other xid's; the helper will be executed in xid 0 only
954 test "$this_xid" = 0 || return 0
956 local proc_file=/proc/sys/kernel/vshelper
958 if ! test -r "$proc_file"; then
960 warnings=( "${warnings[@]}"
961 $"File '$proc_file' does not exist but is required for vshelper setup" )
964 vshelper=$(cat "$proc_file")
966 $_CMP -s "$vshelper" "$_VSHELPER" || {
968 test -r "$vshelper" && readable=1
969 warnings=( "${warnings[@]}"
970 $"The configured vshelper '$vshelper' does not match the 'vshelper'
971 script of the util-vserver package.${readable:+ Maybe you have two versions installed?}"
978 test -d "$__VSHELPERSTATEDIR" || {
979 warnings=( "${warnings[@]}"
981 The vshelper state-directory '$__VSHELPERSTATEDIR' does not exist; since
982 it is created by 'make install', this indicates a serious problem with
983 your util-vserver installation" )
987 test "${#warnings[@]}" -eq 0 || {
989 The following problem(s) were encountered while verifying vshelper
992 for i in "${warnings[@]}"; do
998 To fix this, you can:"
1000 test -z "$solution_disable" || warning $"\
1001 * disable vshelper entirely by executing
1002 | touch \"$__CONFDIR/.defaults/apps/vshelper/disabled\"
1003 * disable only this message by executing
1004 | touch \"$__CONFDIR/.defaults/apps/vshelper/warning-disabled\""
1006 test -x "$solution_sysctl" || warning $"\
1007 * configure the util-vserver vshelper script, e.g. by adding
1008 | kernel.vshelper = $_VSHELPER
1009 to /etc/sysctl.conf and rebooting the machine, or by executing
1010 | echo \"$_VSHELPER\" >$proc_file"
1020 ## Usage: vshelper.isEnabled [<style>] [<vserver>]
1021 function vshelper.isEnabled
1023 local f=${1:+$1-}disabled
1024 test ! -e "$__CONFDIR"/.defaults/apps/vshelper/"$f" || return 1
1025 $_VSERVER_INFO - FEATURE vshelper || return 1
1026 if test -n "$2"; then
1028 appdir=$($_VSERVER_INFO "$2" APPDIR vshelper) || return 0
1029 test -z "$2" -o ! -e "$appdir/$f" || return 1
1035 ## Usage: vshelper.isDebug [<vserver>]
1036 function vshelper.isDebug
1038 test ! -e "$__CONFDIR"/.defaults/apps/vshelper/debug || return 0
1039 $_VSERVER_INFO - FEATURE vshelper || return 1
1040 if test -n "$1"; then
1042 appdir=$($_VSERVER_INFO "$1" APPDIR vshelper) || return 1
1043 test ! -e "$appdir/debug" || return 0
1049 function vshelper._getHandlerInternal
1054 shift ## HACK: see below the note about the 'set -u' mode
1056 while test "$#" -ge 2; do
1061 test "$_vghi_mod" "$_vghi_obj" || continue
1062 case "$_vghi_mod" in
1064 eval $_vghi_var=\$_vghi_obj
1067 read _vghi_tmp <"$_vghi_obj"
1068 eval $_vghi_var=:\$_vghi_tmp
1070 (*) panic $"Internal error, unexpected modifier '$_vghi_mod'"
1078 ## Usage: vshelper.getHandler <result-var> <vserver> <action>
1079 function vshelper.getHandler
1082 _vgh_appdir=$($_VSERVER_INFO "$2" APPDIR vshelper) || _vgh_appdir=
1084 declare -a _vgh_search_list=( X )
1085 ## HACK: when we are in 'set -u' mode, empty lists are causing errors
1087 test -z "$_vgh_appdir" || _vgh_search_list=( "${_vgh_search_list[@]}" -x "$_vgh_appdir/$3" )
1088 test -z "$_vgh_appdir" || _vgh_search_list=( "${_vgh_search_list[@]}" -e "$_vgh_appdir/action" )
1089 _vgh_search_list=( "${_vgh_search_list[@]}" -x "$__CONFDIR"/.defaults/apps/vshelper/"$3" )
1090 _vgh_search_list=( "${_vgh_search_list[@]}" -e "$__CONFDIR"/.defaults/apps/vshelper/action )
1092 ! vshelper._getHandlerInternal "$1" "${_vgh_search_list[@]}" || return 0
1096 ## Usage: vshelper.init <vserver> [<method> <args>*]
1097 function vshelper.doInit
1099 vshelper.isEnabled || return 0
1102 xid=$($_VSERVER_INFO "$1" CONTEXT false) && test -n "$xid" || {
1103 warning $"vshelper.init: can not determine xid of vserver '$vserver'; returned value was '$xid'
1105 This usually means that you're using an init-less init-style, but the
1106 guest isn't configured to start any service. Try enabling a service,
1107 changing the init-style, or making the contexts persistent."
1111 local f="$__VSHELPERSTATEDIR/$xid"
1118 if test -n "$2"; then
1131 ## Usage: vshelper.doDestroy <vserver> <xid>
1132 function vshelper.doDestroy
1134 vshelper.isEnabled || return 0
1136 $_RM -f "$__VSHELPERSTATEDIR/$2"
1139 ## Usage: vshelper.initSync <vserver> <pipe-varname> [<method>]
1140 function vshelper.initSync
1143 _vis_tmpdir=$($_MKTEMPDIR vserver-stop.XXXXXX) || {
1144 warning $"Failed to generate temporary directory for vshelper sync"
1148 local _vis_fifo="$_vis_tmpdir"/pipe
1149 $_MKFIFO -m700 "$_vis_fifo"
1150 vshelper.doInit "$1" "${3:-sync}" "$_vis_fifo"
1154 ## Usage: vshelper.getSyncTimeout <vserver> <varname>
1155 function vshelper.getSyncTimeout
1157 local _vgst_appdir _vgst_file _vgst_tmp
1158 _vgst_appdir=$($_VSERVER_INFO "$1" APPDIR vshelper) || _vgst_appdir=
1160 findFile _vgst_file ${_vgst_appdir:+"$_vgst_appdir"/sync-timeout} "$__CONFDIR"/.defaults/apps/vshelper/sync-timeout ''
1161 test -n "$_vgst_file" || return 1
1162 read _vgst_tmp <"$_vgst_file"
1166 function vshelper.initStopSync
1168 local _iss_sync_dir=$($_MKTEMPDIR vshelper-stop-sync.XXXXXX) || {
1169 warning $"Failed to generate directory for vshelper sync"
1172 $_MKFIFO -m700 "$_iss_sync_dir/pipe"
1174 eval "$1"=\$_iss_sync_dir
1175 VSHELPER_STOP_SYNC="$_iss_sync_dir/pipe"
1176 export VSHELPER_STOP_SYNC
1179 function vshelper.waitForStopSync
1182 cat "$sync_dir/pipe" &> /dev/null
1186 function vshelper.doStopSync
1188 test ! -p "$VSHELPER_STOP_SYNC" || echo stopped > "$VSHELPER_STOP_SYNC"
1191 function vshelper.isStopSync
1193 test -p "$VSHELPER_STOP_SYNC" || return 1
1197 function _rpmFake.getCapFlags
1201 if test -n "$ctx" && ! $_VSERVER_INFO - FEATURE migrate; then
1202 set -- $($_CHCONTEXT_COMPAT --xid 1 \
1203 $_SH -c "$_CAT /proc/[0-9]*/status | $_EGREP '^(CapBset|s_context|ctxflags)'" | \
1204 $_GREP -B 1 -A 1 "^s_context: $ctx " | \
1205 $_SED -e '1,3p;d' | $_AWK '{ print $2 }')
1210 if test -n "$3"; then
1211 RPM_FAKE_CAP=$[ ~0x$1 ]
1214 RPM_FAKE_CAP=$[ ~0xd40c04ff ]
1219 function rpmFake.init
1223 vdir=$($_VSERVER_INFO "$1" VDIR) || vdir="$1"
1224 ctx=$($_VSERVER_INFO "$1" CONTEXT) || ctx=
1227 panic $"Can not find chroot environment at '$vdir' for '$1'"
1229 _rpmFake.getCapFlags "$ctx"
1231 RPM_FAKE_CHROOT=$vdir
1235 function rpmFake.exec
1237 export RPM_FAKE_CHROOT RPM_FAKE_CTX RPM_FAKE_CAP RPM_FAKE_FLAGS
1239 LD_PRELOAD=$_RPM_FAKE_SO${LD_PRELOAD:+:$LD_PRELOAD} \