#!/bin/ksh -pu
#
# ident "@(#)utidle.sh	1.5 04/04/14 SMI"
#
# Copyright 1999,2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

#
# Examples:
#	/opt/SUNWut/lib/utidle /var/opt/SUNWUt/displays/9 true
#	/opt/SUNWut/lib/utidle /var/opt/SUNWUt/displays/121 false

ME=$0

# Parse arguments

eval $(sed -n 's/SESSION=\([^:]*\):\([^:\]*\):\(.*\)$/host=\1\
port=\2\
sid=\3/p' $1)

idle=$2

if [ -z "$host" -o -z "$port" -o -z "$sid" -o -z "$idle" ]
then
	exit 1;
fi


# translate a host name to its IP address
function getHostIPA {
	host=$1
	if [ "$host" = "$(hostname)" ]
	then
		print 0.0.0.0
		return
	fi
	case $host in
	localhost | 127.0.0.1 | 0.0.0.0)
		print 0.0.0.0
		return;;
	esac

	hostipa=$(getent hosts $host 2>/dev/null | cut -f1 -d'	')
	print $hostipa
}

ipa=$(getHostIPA $host)

UTLIB=/etc/opt/SUNWut/basedir/lib
UTPIPE=${UTLIB}/utnetpipe

print "control $host:$port:$sid\nrequest annotate\nidle=$idle\nend\n" \
| $UTPIPE $ipa 7010 > /dev/null 2>&1

#
# we just send the message, we don't need to confirm.
#

exit 0
