# -* sh path added by autoconfiscator      *-
#
# Copyright (c) 2001-2002 by Leni Mayo
#
#	This program is free software; you can redistribute it and/or modify
#	it under the terms of the GNU General Public License, version 2, as
#	published by the Free Software Foundation.
#
#	This program is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.
#
# echo $* >> /tmp/serel-wrap.log
#
# Eventually, this shell script will disappear to be replaced
# by a C program for efficiency - the time program (see: "man 1 time")
# is an example of the sort of thing.

if [ $# != 2 ]; then
	echo "Usage: $0 path {start | stop}"
	exit 1
fi

# create a shell in the background that does the dependencies,
# then exec's the script.  exec is necessary 'cos its the ppid that
# ties together the script and the need/provide/unprovide.
#
# set -x

$SH --norc --noprofile -s $@ <<- "END" &
	# set -x
	serelhistory --apply $1
	[ $? = 0 ] && exec $@
	END

pid=$!

# If all works well, this trap will be trying to kill processes
# that don't exist.  When something breaks, or if this script
# gets killed, the trap kills processes that would otherwise becomes zombies.
# We probably also want to do a statuschange in that scenario, but we'd 
# need to first query that one hadn't been done.
#
trap "kill $pid > /dev/null 2>&1 " EXIT

wait $pid
status=$?
serelc --statuschange $pid $status

exit $status
