#!/bin/sh
set -e

do_help() {
        cat <<END
saref - bind process to given SAref

   saref <saref> <command> <options...>

END
        exit 0
}

[ -z "$1" ] && do_help

case "$1" in 
-h|--help)
        do_help
        ;;
esac

export IPSEC_SAREF="$1"
shift

if [ "$IPSEC_SAREF" -lt 0 ] || [ "$IPSEC_SAREF" -gt 65536 ] ; then
        echo >&2 "Error: invalid SAref value of $IPSEC_SAREF"
        exit 1
fi

dir=$(dirname $0)

export LD_PRELOAD="$dir/libsaref.so $LD_PRELOAD"
exec ${@}
