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

# 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/kdm ]; then
    /usr/bin/mkdir /dev/kdm
    /usr/bin/chmod 755 /dev/kdm
  fi
  /usr/bin/touch /dev/kdm/$devname
  /usr/bin/chmod 644 /dev/kdm/$devname

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