#!/sbin/sh
#
# @(#) $Revision: 1.2.212.1 $
#
#           Copyright (C) 1993, 1994 Hewlett-Packard Company
#
# NOTE:    This script is not configurable!  Any changes made to this
#          script will be overwritten when you upgrade to the next
#          release of HP-UX.
#

#
# Dedicated Ports Parser starts Outbound Connection Daemons
# Used by DDFA software
#

PATH=/sbin:/usr/sbin:/usr/bin
export PATH

rval=0
set_return() {
        x=$?
        if [ $x -ne 0 ]; then
                echo "EXIT CODE: $x"
                rval=1  # always 1 so that 2 can be used for other reasons
        fi
}

case $1 in
'start_msg')
	echo "Starting outbound connection daemons for DDFA software"
	;;

'stop_msg')
	echo "Stopping outbound connection daemons for DDFA software"
	;;

'start')
        if [ -f /etc/rc.config ] ; then
		. /etc/rc.config
	else
		echo "ERROR: /etc/rc.config defaults file MISSING"
	fi
	
	if [ "$DDFA" -eq 1 ] ; then
		# Start DTC device file access (DDFA)
		# The configuration files need to be copied from the directory
		#    /usr/examples/ddfa into /etc/ddfa
		#
		if [ -x /usr/sbin/dpp -a -x /usr/sbin/ocd -a -f /etc/ddfa/dp ] ; then
			/usr/sbin/dpp /etc/ddfa/dp && echo "dpp  \c"
			set_return
		fi
	else
		rval=2
	fi
	;;

'stop')
	if [ -f /etc/rc.config ] ; then
		. /etc/rc.config
	else
		echo "ERROR: /etc/rc.config defaults file MISSING"
	fi

	if [ "$DDFA" -eq 1 ] ; then
		# Stop DTC device file access (DDFA)
		# Determine PID of ocd daemons to stop
		#
		status=0
		pid=`ps -e | awk '$NF~/ocd/ {print $1}'`
		for p in $pid
		do
			kill -TERM $p
			if [ $? -ne 0 ] ; then
				set_return
				status=1
			fi
		done
		if [ "$status" = 0 ] ; then
			echo "All ocd(s) stopped"
		else
			echo "Unable to stop ocd(s)"
		fi
	else
		rval=2
	fi
        ;;

*)
	echo "usage: $0 {start|stop|start_msg|stop_msg}"
	rval=1
	;;
esac

exit $rval
