#!/bin/sh
#
# Wrapper for the real binary. Ensure that the binary will find all
# the shared libraries it needs. If a shared library is not available from any
# of the standard system-wide locations, we provide it from the build
# directory. --hpreg
#

# Use readlink only when necessary: some boxes don't have it, some boxes have
# one that does not support the -f option. --hpreg
# XXX Multiple copies of the same code. Need to consolidate into a common location
if [ -h "$0" ]; then
   this="`readlink -f "$0"`"
else
   this="$0"
fi

libdir=/usr/lib/vmware-rhttpproxy
binary="`basename "$this" .sh`"
defaultArgs=

abslibdir="`cd \"$libdir\" 2>/dev/null && pwd || echo \"$libdir\"`"
# Generate cores even in release env
ulimit -c unlimited

# Raise the number of file descriptors that can be opened.
# No more than FD_SETSIZE_HUGE, see PR 689249, cl 7151.
ulimit -n 10000

if [ "$PID_FILE" ]; then
    echo $$ > "$PID_FILE"
fi

export LD_LIBRARY_PATH="$abslibdir:/usr/lib/vmware-vmafd/lib64:/opt/likewise/lib64/"

LD_ASSUME_KERNEL=$LD_ASSUME_KERNEL \
LD_PRELOAD="$VMW_PRELOAD" \
   exec $DEBUG_CMD "$libdir"/$binary $defaultArgs "$@"

