#!/bin/sh
#
# disconnect a user, first getting a stack trace (if possible)
#
# $1 = pdbname
# $2 = usr#
# $3 = PID (if local)

. #ENVPT3#/bin/protopenv

TMPDIR=${TMPDIR-/tmp}
LOGDIR=${LOGDIR-/tmp}

PROTRACE=${PROTRACE-/home}						# where to look for protrace files
									# define in bin/localenv if necessary
XPID=${3-remote}
SCRATCH=${TMPDIR}/disconnect.tmp

echo "" >>  ${SCRATCH}
echo "Disconnecting user ${2} from ${1}" >> ${SCRATCH}

if [ ! -z "${3}" ]
then
	echo "\$DLC/bin/proGetStack ${3}" >> ${SCRATCH}
	proGetStack ${XPID} >> ${SCRATCH}
fi

proshut ${1} -C disconnect ${2} >> ${SCRATCH}

if [ -z "${3}" ]
then
	echo "Not a local session, no stack trace available" >> ${SCRATCH}
else
	find ${PROTRACE} -name "protrace.${XPID}" -exec cat {} \; >> ${SCRATCH}
fi

# local extensions go in this script -- if disconn.local exists, run it
#
# $1 = pdbname
# $2 = usr#
# $3 = PID (if local)

if [ -f ${PROTOP}/bin/disconn.local ]
then
        ${PROTOP}/bin/disconn.local ${1} ${2} ${3}
fi

