#!/bin/sh
# $XConsortium: Xsession,v 1.7 92/08/06 11:08:14 gildea Exp $

# redirect errors to a file in user's home directory if we can
for errfile in "$HOME/.xsession-errors" "/tmp/xses-$USER"
do
	if ( cp /dev/null "$errfile" 2> /dev/null )
	then
		chmod 600 "$errfile"
		exec > "$errfile" 2>&1
		break
	fi
done

case $# in
1)
	case $1 in
	failsafe)
		exec xterm -geometry 80x24-0-0
		;;
	esac
esac


# Since xdm doesn't run a bash -login shell (or any other login shell)
# then read the files that it would, to set up the user's environment
profile=/etc/profile
userprofile=~/.profile

if [ -e $profile ]; then
        source $profile
fi
if [ -e $userprofile ]; then
        source $userprofile
fi

# If the user doesn't have their own xsession, then run openwin or
# xinitrc if they exist
startup=$HOME/.xsession
sysstartup1=$OPENWINHOME/bin/openwin
sysstartup2=/usr/X11/lib/X11/xinit/xinitrc
resources=$HOME/.Xresources

if [ -f $startup ]; then
        exec $startup
elif [ -f $sysstartup1 ]; then
        exec $sysstartup1
elif [ -f $sysstartup2 ]; then
        exec $sysstartup2
else
        if [ -f $resources ]; then
                xrdb -load $resources
        fi
        twm &
        exec xterm -geometry 80x24+10+10 -ls
fi
