#!/bin/bash
#
# SMC Tools - Shared Memory Communication Tools
#
# Copyright IBM Corp. 2017, 2018
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
LIB_NAME="libsmc-preload.so"

#
# Verify command line arguments and specify the preload library debug mode
# if necessary.
#
command_line=$@
debug_option=$(echo "$command_line" | cut -f 1 -d " ");
SMC_DEBUG=0;
while getopts ":d" opt; do
	case $opt in
		d)
			SMC_DEBUG=1;
			command_line=${command_line#"$debug_option"};
			command_line=${command_line##\ };
			;;
		\?)
			echo "`basename "$0"`: Error: Invalid option: -$OPTARG";
			exit 1;
			;;
	esac
done
if [ "x$command_line" = "x" ]; then
	echo "`basename "$0"`: Error: Missing command parameter";
	exit 1;
fi

export SMC_DEBUG;
#
# Execute the specified command.
#
export LD_PRELOAD=$LD_PRELOAD:$LIB_NAME;

exec $command_line
exit $?;
