#!/bin/ksh
#
# ident "@(#)Xcleanup.sh	1.7 04/02/09 SMI"
#
# Copyright 1999-2001,2004 Sun Microsystems, Inc.  All rights reserved.
#

#
# Product:	Sun Ray server	3.1
#
# Purpose:	Cleanup an inactive X server in dtgreet
#

#
# We commit suicide because we're in dtgreet and have been
# disconnected for a while
#

export LC_ALL=C

DEVICE_PKG_LOC="`/etc/opt/SUNWut/basedir/lib/utprodinfo -r SUNWuto`/SUNWut"
DEVICE_LIB=$DEVICE_PKG_LOC/lib
IDLEDIR=/var/opt/SUNWut/idle

if [ "$SUN_SUNRAY_TOKEN" != "" -a -x $DEVICE_LIB/utdtsession ]
then
	UTPID=""

	DPY=${DISPLAY#*:}
	DPY=${DPY%.*}

	if [ "$DPY" != "" ]
	then
		if [ -f $IDLEDIR/$DPY.pid ]
		then
			#
			# stop the utaction
			#
			UTPID=$(/bin/cat $IDLEDIR/$DPY.pid)
			/bin/rm -f $IDLEDIR/$DPY.pid
		fi
		/bin/rm -f $IDLEDIR/$DPY.info
	fi

	$DEVICE_LIB/utdtsession -t "$SUN_SUNRAY_TOKEN" delete \
		< /dev/null > /dev/null 2> /dev/null

	if [ "$UTPID" != "" ]
	then
		kill $UTPID
	fi
fi
