#!/sbin/sh
#
# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
#
# ident	"@(#)print-svc	1.2	07/11/09 SMI"
#

. /lib/svc/share/smf_include.sh

# SERVICE = parent service name
SERVICE=`echo $SMF_FMRI | /usr/bin/cut -f1,2 -d":"`

case "$1" in
'start')

isopts=`/usr/sbin/svccfg <<-EOF
	select $SMF_FMRI
	listpg cmd_opts

	EOF`

if [ "$isopts" ] ; then

#called by /usr/lib/lpsched; use cmd_opts properties only

	num_notifiers=`/bin/svcprop -p cmd_opts/num_notifiers $SMF_FMRI`

	if [ "$num_notifiers" != "" ] ; then
		OPTS="$OPTS -n $num_notifiers" 
	fi

	num_filters=`/bin/svcprop -p cmd_opts/num_filters $SMF_FMRI`

	if [ "$num_filters" != "" ]  ; then
		OPTS="$OPTS -f $num_filters"
	fi

	fd_limit=`/bin/svcprop -p cmd_opts/fd_limit $SMF_FMRI`

	if [ "$fd_limit" != "" ]  ; then
		OPTS="$OPTS -p $fd_limit"
	fi

	reserved_fds=`/bin/svcprop -p cmd_opts/reserved_fds $SMF_FMRI`

	if [ "$reserved_fds" != "" ] ; then
		OPTS="$OPTS -r $reserved_fds"
	fi

# clear out cmd_opts property group

	svccfg <<-EOF
	select $SMF_FMRI
	delpg cmd_opts

	EOF

else

# We are here through enable; use lpsched properties
# Check for saved properties

	num_notifiers=`/bin/svcprop -p lpsched/num_notifiers $SERVICE`
	if [ "$num_notifiers" != "" ] && [ "$num_notifiers" != "0" ] ; then
		OPTS="$OPTS -n $num_notifiers"
	fi

	num_filters=`/bin/svcprop -p lpsched/num_filters $SERVICE`
	if [ "$num_filters" != "" ] && [ "$num_filters" != "0" ] ; then
		OPTS="$OPTS -f $num_filters"
	fi

	fd_limit=`/bin/svcprop -p lpsched/fd_limit $SERVICE`
	if [ "$fd_limit" != "" ]  && [ "$fd_limit" != "0" ]; then
		OPTS="$OPTS -p $fd_limit"
	fi

	reserved_fds=`/bin/svcprop -p lpsched/reserved_fds $SERVICE`
	if [ "$reserved_fds" != "" ] && [ "$reserved_fds" != "0" ] ; then
		OPTS="$OPTS -r $reserved_fds"
	fi
fi

# set temporary or permanent properties from OPTS

	[ -f /usr/lib/lp/local/lpsched ] || exit $SMF_EXIT_ERR_CONFIG

	/usr/lib/lp/local/lpsched ${OPTS}

	;;

'stop')
	[ -f /usr/lib/lp/local/lpshut ] || exit $SMF_EXIT_ERR_CONFIG

	/usr/lib/lp/local/lpshut
	;;

*)
	echo "Usage: $0 { start | stop }"
	exit 1
	;;
esac
exit $SMF_EXIT_OK
