findFile tmp "$@"
test "$tmp" -a -s "$tmp" || return 0
- cp -af "$tmp" "$dst"
+ $_CP -af "$tmp" "$dst"
}
function getPhysicalDir
local style=$1
shift
- if ! tty -s; then
+ if ! $_TTY -s; then
"$@"
else
local cfile
findFile cfile "$CONFDIR"/.defaults/styles/"$style" ''
if test "$cfile"; then
- cat "$cfile"
+ $_CAT "$cfile"
else
case "$style" in
(bold) echo -ne "\e[1m";;
## Usage: xtermTitle <title>
function xtermTitle
{
- tty -s || return 0
+ $_TTY -s || return 0
echo -ne "\e]0;$@\007"
}
## Usage: lock <lockfile> [<timeout>]
function lock
{
- local tmp=$(mktemp /tmp/vserver-lock.XXXXXX)
- rm -f $tmp
- mkfifo -m600 $tmp
+ local tmp=$($_MKTEMP /tmp/vserver-lock.XXXXXX)
+ $_RM -f $tmp
+ $_MKFIFO -m600 $tmp
$_LOCKFILE "$1" $tmp $2 &
- grep -q true $tmp 2>/dev/null || return 1
+ $_GREP -q true $tmp 2>/dev/null || return 1
_VS_LOCKS="$! $_VS_LOCKS"
}
{
test "$1" != "$2" || return 0
- mount -n --bind "$1" "$2"
+ $_MOUNT -n --bind "$1" "$2"
}
function _pkgSetVarsBase
_pkgMountBindDir "$RPMETCDIR" /etc/rpm
test "$RPMLIBDIR" = "/" || _pkgMountBindDir "$RPMLIBDIR" /usr/lib/rpm
- "$_SECURE_MOUNT" --chroot "$VDIR" -n --secure --bind "$RPMSTATEDIR" "$_rpmdb_mntpoint"
+ pushd "$VDIR" >/dev/null
+
+ $_SECURE_MOUNT --chroot -n --bind "$RPMSTATEDIR" "$_rpmdb_mntpoint"
test -z "$WORKAROUND_106057" || mount -n --bind "$RPMSTATEDIR" "$_rpmdb_mntpoint"
test -e "$VDIR"/proc/self/status || \
- "$_SECURE_MOUNT" --chroot "$VDIR" -n --secure -t proc none /proc
+ $_SECURE_MOUNT --chroot -n -t proc none /proc
+
+ popd >/dev/null
}
function _pkgSetEnvBase
eval $1='( "${_tmp[@]}" )'
}
+## Usage: _getProcNumberCount <ctx> <var>
+function _getProcNumberCount
+{
+ local var=$2
+ local procnr_cnt=0
+
+ # Use /proc/virtual from kernel 2.6 when possible
+ if test -d "/proc/virtual"; then
+ set -- $($_GREP '^PROC:' "/proc/virtual/$1/limit" 2>/dev/null)
+ procnr_cnt=$2
+ else
+ procnr_cnt=$($_VPS ax | $_AWK '{print $2}' | $_GREP -x "$1" | $_WC -l )
+ fi
+
+ let procnr_cnt=procnr_cnt+0
+ eval $var=\$procnr_cnt
+}
+
## Usage: getVserverCtx <vdir> <result-varname> [<procnumber-varname> [<do-cleanup>]]
## Returns: 0 iff vserver is running
function getVserverStatus
eval "$2"=\$_ctx
test "$3" || return 0
- local _tmp=$($_VPS ax | $_AWK '{print $2}' | $_GREP -x "$_ctx" | $_WC -l )
- let _tmp=_tmp+0
+ local _tmp
+ _getProcNumberCount "$_ctx" _tmp
eval "$3"=\$_tmp
if test "$_tmp" = 0; then
local runfile=$($_READLINK "$1/run")
- test -z "$4" || rm -f "$runfile"
+ test -z "$4" || $_RM -f "$runfile"
return 1
fi
## Usage: isCtxRunning <ctx>
function isCtxRunning
{
- local _tmp=$($_VPS ax | $_AWK '{print $2}' | $_GREP -x "$1" | $_WC -l )
+ local _tmp
+ _getProcNumberCount "$1" _tmp
test $_tmp -gt 0
}
return 0
}
-## Called as 'getFileValue <varname> <filename>'
+## Called as 'getFileValue <varname> <filename>+'
function getFileValue
{
- test -r "$2" || return 0
- eval read "$1" <"$2"
+ local var=$1
+ local file
+ shift
+
+ findFile file "$@" ''
+ test "$file" -a -r "$file" || return 0
+ eval read "$var" <"$file"
}
## Called as 'getFileArray <varname> <filename>'
for i; do
local failed=
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;;
- *) echo "Unknown component '$i'" >&2
+ (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;;
+ (*) echo "Unknown component '$i'" >&2
return false
;;
esac
else
vshelper=$(cat "$proc_file")
- cmp -s "$vshelper" "$_VSHELPER" || {
+ $_CMP -s "$vshelper" "$_VSHELPER" || {
warnings=( "${warnings[@]}"
$"The configured vshelper '$vshelper' does not match the 'vshelper'
script of the util-vserver package"
local f="$VSHELPERSTATEDIR/$xid"
set -C
- rm -f "$f"
+ $_RM -f "$f"
echo "$1" >"$f"
set +C
{
vshelper.isEnabled || return 0
- rm -f "$VSHELPERSTATEDIR/$2"
+ $_RM -f "$VSHELPERSTATEDIR/$2"
}
## Usage: vshelper.initSync <vserver> <pipe-varname>
function vshelper.initSync
{
- local tmpdir=$(mktemp -d /tmp/vserver-stop.XXXXXX) || {
+ local tmpdir=$($_MKTEMPDIR /tmp/vserver-stop.XXXXXX) || {
warning $"Failed to generate temporary directory for vshelper sync"
return 1
}
local fifo="$tmpdir"/pipe
- mkfifo -m700 "$fifo"
- vshelper.doInit "$VSERVER_DIR" sync "$fifo"
+ $_MKFIFO -m700 "$fifo"
+ vshelper.doInit "$1" sync "$fifo"
eval $2=\$fifo
}