#!/bin/sh 

# Top level Xsession file for all users
#
# $Id: Xsession,v 1.14 96/01/28 15:35:02 svalente Exp $

trap "kdestroy; unlog; fsid -u -f $USER; exit 0" 1 2 15

initlib="/usr/athena/lib/init"
defsession=$1
defsessioncmd="$2"

case $defsession in
1|4)
	if [ -f .xsession ]; then
		session="./.xsession"
	else
		session="$initlib/xsession"
	fi
	;;
2)
	session="$initlib/xsession -nocalls"
	;;
3)
	session="xterm -ls -geometry 80x24+280+220 -display :0.0"
	;;
5)
	session="$defsessioncmd"
	;;
7)
	session=/usr/vue/config/Xsession
	;;
esac

# Set the tty characteristics of the parent (console window)
# Redirect stdin since some versions of stty use it instead of stdout.
if [ "${hosttype}" = "decmips" ]; then
  stty dec 0<&1 2>/dev/null
else
  if [ "${hosttype}" != "hp" ]; then
    stty sane 0<&1 2>/dev/null
  fi
fi

# Make random Athena modifications to keymap if required.

test -f /usr/athena/lib/X11/keymaps/AthenaMods && \
  xmodmap /usr/athena/lib/X11/keymaps/AthenaMods

$session

status=$?
if [ $status != 0 ]; then
		echo ERROR:
		echo "Xsession returned non-zero status."
		echo ""
		echo 'Select the login option to "Ignore your customizations"'
		echo 'to login and repair your dot files.'
		kdestroy			# destroy tickets.
		sleep 10
		exit $status
fi


# Cannot detach homedir here, since this script is executed in the users
# homedir.

kdestroy				# destroy tickets.
cd /tmp
unlog
fsid -u -f $USER > /dev/null 2>&1
sleep 3					# let them see any messages (quickly)
exit 0
