#! /sbin/sh
#
# NOTE:    This script is not configurable!  Any changes made to this
#          scipt will be overwritten when you upgrade to the next
#          release of HP-UX.
#
# WARNING: Changing this script in any way may lead to a system that
#          is unbootable.  Do not modify this script.
#

#
# Not supported on all systems
# ptydaemon allocates pty's to various processes
#

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

rval=0
set_return() {
	x=$?
	if [ $x -ne 0 ]; then
		echo "EXIT CODE: $x"
		rval=1
	fi
}


case $1 in
start_msg)
	echo "Start pty allocator daemon"
	;;

stop_msg)
	echo "Stop pty allocator daemon"
	;;

'start')
	if [ -f /etc/rc.config.d/ptydaemon ] ; then
		. /etc/rc.config.d/ptydaemon
	else
		echo "ERROR: /etc/rc.config.d/ptydaemon file MISSING"
	fi
	if [ $PTYDAEMON_START -eq 1 -a  -x /usr/sbin/ptydaemon ]
	then
		echo "Starting the ptydaemon"
		/usr/sbin/ptydaemon
		set_return
	else
		rval=2
	fi
	;;

'stop')
        #
	# Determine PID of process(es) to stop
	#
	pid=`ps -el | awk '( ($NF ~ /ptydaemon/) && ($4 != mypid) && ($5 != mypid)  ){ print $4 }' mypid=$$ `
	if [ "X$pid" != "X" ]; then
		if kill $pid; then
			echo "Ptydaemon stopped"
		else
			set_return
			echo "Unable to stop ptydaemon"
		fi
	fi
	;;

*)
	echo "usage: $0 {start|stop}"
	;;
esac

exit $rval
