#! /bin/sh
# Xstartup - run as root before session starts

PIDFILE=/var/run/kdmdesktop-$DISPLAY.pid
if [ -f $PIDFILE ] ; then
     kill `cat $PIDFILE`
fi

# By convention, both xconsole and xterm -C check that the
# console is owned by the invoking user and is readable before attaching
# the console output.  This way a random user can invoke xterm -C without
# causing serious grief.
# This is not required if you use PAM, as pam_console should handle it.
#
chown $USER /dev/console

# We create a pseudodevice for finger.  (host:0 becomes kdm/host_0)
# Without it, finger errors out with "Can't stat /dev/host:0".
#
if [ -f /usr/lib/X11/xdm/sessreg ]; then
  devname=`echo $DISPLAY | /usr/bin/sed -e 's/[:\.]/_/g' | /usr/bin/cut -c1-8`
  hostname=`echo $DISPLAY | /usr/bin/cut -d':' -f1`

  if [ -z "$devname" ]; then
    devname="unknown"
  fi
  if [ ! -d /dev/xdm ]; then
    /usr/bin/mkdir /dev/xdm
    /usr/bin/chmod 755 /dev/xdm
  fi
  /usr/bin/touch /dev/xdm/$devname
  /usr/bin/chmod 644 /dev/xdm/$devname

  if [ -z "$hostname" ]; then
    exec /usr/lib/X11/xdm/sessreg -a -l xdm/$devname $USER
  else
    exec /usr/lib/X11/xdm/sessreg -a -l xdm/$devname -h $hostname $USER
  fi
fi
