#!/sbin/sh
#
# @(#) $Revision: 72.12 $
#
# 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.
#

#
# System message logger
#

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
}


################################################################################
# Arguments:                                                                   #
#            Name of the Process whose ids should be returned.                 #
#                                                                              #
# Description:                                                                 #
# This routine returns a list of process ids whose name matches the argument   #
# to this function. It also ensures that the process id list does not include  #
# the process id of the current process.                                       #
#                                                                              #
# Return Value:                                                                #
#          "" : if there's no process by this name                             #
#          List of process ids separated by space if process name is found     #
#                                                                              #
################################################################################

GetNamedProcIds()

{
	ps -e | awk -v mypid=$$	-v pname=$1			\
			'$NF~pname {				\
				if ($1 != mypid)		\
					print $1		\
			}'
}

case $1 in
'start_msg')
	echo "Start system message logging daemon"
	;;

'stop_msg')
	echo "Stop system message logging daemon"
	;;

'start')
	if [ -x /usr/sbin/syslogd -a -f /etc/syslog.conf ]; then
		if [ -f /var/adm/syslog/syslog.log ]; then
			mv /var/adm/syslog/syslog.log /var/adm/syslog/OLDsyslog.log
			mask=`umask`
			umask 022
			> /var/adm/syslog/syslog.log
			umask $mask
		fi
		pids=`GetNamedProcIds "syslogd"`
		if [ "X$pids" != "X" ]; then
			kill $pids 1>/dev/null 2>&1
		fi
		/usr/sbin/syslogd -D &&
			echo "System message logger started"
		set_return
	else
		echo "Unable to start syslogd:"
		echo "Daemon and/or conf file missing and/or incorrect permissions"
		rval=2
	fi

	;;

'stop')
	#
	# Determine PIDs of process(es) to stop
	#
	pids=`GetNamedProcIds "syslogd"`

	kill $pids 1>/dev/null 2>&1
	echo "syslogd stopped"

	# Set return value to be zero.

	rval=0; 

	;;

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

exit $rval
