#!/bin/sh
#
# /etc/X11/xdm/Xreset
#
# This script is run as root after the X session ends.

PATH=$PATH:/usr/bin/X11
HOSTSERVER=$(echo $DISPLAY | cut -d. -f1)
PIDFILE=/var/run/xconsole.$HOSTSERVER.pid

if [ -e $PIDFILE ]; then
  PID=$(cat $PIDFILE 2> /dev/null)
  if [ -n "$PID" ]; then
    kill $PID 2> /dev/null
  fi
  rm $PIDFILE
fi

# Run /etc/syslogout being $USER
su - $USER -c "if [ -f /etc/syslogout ]; then . /etc/syslogout; fi"

# remove the utmp entry for the session
if grep -qs ^use-sessreg /etc/X11/xdm/xdm.options && command -v sessreg > /dev/null 2>&1; then
  sessreg -d -l $DISPLAY -u /var/run/utmp -x /etc/X11/xdm/Xservers $USER
fi

exit 0

# vim:set ai et sts=2 sw=2 tw=0:
