#! /bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
#  
#  
# Licensed Materials - Property of IBM 
#  
# (C) COPYRIGHT International Business Machines Corp. 2000,2007 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
#*===========================================================================*/
#*                                                                           */
#* Module Name:  rmcd_start                                                  */
#*                                                                           */
#* Description:                                                              */
#*      Script to start the Resource Monitor & Control Daemon                */
#*                                                                           */
#* N.B. This command is intended to be executed by the RMC subsystem only !! */
#*                                                                           */
#*===========================================================================*/
#*   @(#)58   1.8.1.5   src/rsct/rmc/mcdaemon/rmcd_start.sh, mcdaemon, rsct_relgh, relghs001a 1/30/06 20:35:25 

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

FIRST=/var/ct/first_start
FIRST_LOG=/var/ct/first.log
START_PORT_FILE=/var/ct/cfg/ctrmc.rpe
MSG_POLICY_FILE=/var/ct/cfg/ctrmc.msgp
DMSG_POLICY_FILE=/var/ct/cfg/ctrmc.dmsgp
TIMEOUT_OPTS_FILE=/var/ct/cfg/ctrmc.topts

REDHAT_RELFILE="/etc/redhat-release"
REDHAT_VERSION="^Red Hat Enterprise Linux .* release 3 (.*)$"
SUSE_RELFILE="/etc/SuSE-release"
SUSE_VERSION="^SUSE LINUX Enterprise Server 9 (.*)$"

# sed string to extract subsystem state from "lssrc -s <subsys>" output
PARSE_SRC_STATE="-e1d;s/.* \([a-zA-Z0-9]*\)$/\1/"

# if the first start file is present, start the ctfirst script in the
# background.

if [[ -a $FIRST ]]
then
	ctfirst > $FIRST_LOG 2>&1 &
fi

# check if remote clients are to be accepted

if [[ -a $START_PORT_FILE ]]
then
	ROPT="-r"
else
	ROPT=
fi

# check if client message authentication policy is to be set

MOPT=
if [[ -s $MSG_POLICY_FILE ]]
then
	POLICY=$(< $MSG_POLICY_FILE)
	case $POLICY in
		R ) MOPT="-m" ;;
		D ) MOPT="-M" ;;
	esac
fi

# check if daemon-to-daemon message authentication policy is to be set

NOPT=
if [[ -s $DMSG_POLICY_FILE ]]
then
	POLICY=$(< $DMSG_POLICY_FILE)
	case $POLICY in
		R ) NOPT="-n" ;;
		D ) NOPT="-N" ;;
	esac
fi

# check if running on RH EL release 3 or SLES 9. If so, special processing

if [[ -f $REDHAT_RELFILE ]]
then
	grep "$REDHAT_VERSION" $REDHAT_RELFILE > /dev/null 2>&1
	if (($? == 0))
	then
		export LD_ASSUME_KERNEL=2.4.19
	fi
elif [[ -f $SUSE_RELFILE ]]
then
	grep "$SUSE_VERSION" $SUSE_RELFILE > /dev/null 2>&1
	if (($? == 0))
	then
		export LD_ASSUME_KERNEL=2.4.19
	fi
fi

# check for timeout options

TOPT=
UOPT=
VOPT=
WOPT=
XOPT=
if [[ -s $TIMEOUT_OPTS_FILE ]]
then
	while read Flag junk
	do
		case $Flag in
			MSG_TIMEOUT* )
					FlagValue=${Flag#MSG_TIMEOUT=}
					TOPT="-t $FlagValue"
					echo $TOPT
					;;
			START_TIMEOUT* )
					FlagValue=${Flag#START_TIMEOUT=}
					UOPT="-u $FlagValue"
					echo $UOPT
					;;
			CMD_TIMEOUT* )
					FlagValue=${Flag#CMD_TIMEOUT=}
					VOPT="-v $FlagValue"
					echo $VOPT
					;;
			CMD_THRESHOLD* )
					FlagValue=${Flag#CMD_THRESHOLD=}
					WOPT="-w $FlagValue"
					echo $WOPT
					;;
			CMD_AUTHENT_ENABLE  )
					XOPT=-x
					echo $XOPT
					;;
		esac
	done < $TIMEOUT_OPTS_FILE
fi

#define resource classes that support new ACLs

AOPT="-a IBM.LPCommands"

# now start the RMC daemon in the current process so it is the child of the
# SRC subsystem daemon

unset EXTSHM
exec /usr/sbin/rsct/bin/rmcd $AOPT $ROPT $MOPT $NOPT \
		$TOPT $UOPT $VOPT $WOPT $XOPT  $@

