#!/bin/ksh
#
# ident "@(#)smcwbemserver.sh	1.27 05/11/14 SMI"
# Copyright (c) 2000 Sun Microsystems, Inc.
# All Rights Reserved.

. ${VIPER_HOME}/lib/functions

# add WBEM CLASSPATH and LD_LIBRARY_PATH
# we have to find out where WBEM stuff resides
# 1) if this is run from workspace
# 2) if this is run from toolkit
# 3) if this is run from installed packages..(most likely)
#
# Right now we force user to have /usr/sadm/lib/wbem dir with
# appropriate jars and libs in place.

WBSERHOME=${WBBASEDIR:-/}usr/sadm
WBSERLIB=${WBSERHOME}/lib/wbem

LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${WBSERLIB}:/usr/snadm/lib
PATH=${PATH}:/usr/sbin

CLASSPATH=${WBSERLIB}:${VIPER_JSDK}:${JARPATH}/smcwbemserver_rt.jar:${SERVER_RT}:${CLASSPATH}:${WBSERLIB}/prodregapi.jar:${WBSERLIB}/jini-core.jar:${WBSERLIB}/jini-ext.jar:${WBSERLIB}/outrigger.jar:${WBSERLIB}/transient-outrigger.jar:${WBSERLIB}/cimrepository.jar:${WBSERLIB}/snmpprovider.jar:${WBSERLIB}/jsnmpapi.jar:${WBSERLIB}/nativeprovider.jar:${WBSERLIB}/osserver.jar:${WBSERLIB}/mofcomp.jar:${WBSERLIB}/suncimom.jar:${WBSERLIB}/sunwbem.jar:${WBSERLIB}/wbemstartup.jar:${AUDITJAR}

umask 022

# Add code to prevent the RMI GC Deamon from running every minute
JAVARMIOPTS="-Dsun.rmi.dgc.server.gcInterval=0x7fffffffffffffff -Dsun.rmi.dgc.client.gcInterval=360000"

${JAVA} "${JAVAARGS[@]}" \
	-Xmx128m \
	-Dsun.security.key.serial.interop=true \
	-Djava.security.policy=${VIPER_HOME}/policy/smcwbemserver.policy \
	-Dviper.argv0=$0 \
	-Dviper.home=${VIPER_HOME} \
	-Dviper.rthome=${SMC_RTHOME} \
	-Dviper.display=${X_DISPLAY} \
	-Dpropdir=${WBSERLIB} \
	${JAVARMIOPTS} \
	com.sun.management.viperimpl.server.ViperWbemServer "$@" |&

# Get information about the server command we just started
. "${VIPER_HOME}/lib/server_track.1"

while true; do
	sIFS="$IFS"
	IFS="
"
	read -p bkg
	[ $? -ne 0 ] && exit 1
	IFS="sIFS"
	if expr "$bkg" : '^[0-9]$' > /dev/null 2>&1; then
		code=$bkg
		break
	fi
	echo "$bkg"
done

# Get status of server command and do any cleanup in case
# it's in an unstable state.
. "${VIPER_HOME}/lib/server_track.2"

exit $code
