#!/bin/ksh -p
#
# ident "@(#)gdm-reset-dpy.sh	1.5 04/06/24"
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
#
# Script to reinitialize empty state for GDM
# Pass SRSS config directory as first arg (e.g. reset-dpy /tmp/SUNWut/config)
#

CONFIGDIR=$1
CONFIGXDIR=$CONFIGDIR/xconfig
DMNAME=gdm-binary

# Note - we start MINDISP at 11 using gdm for linux. It gets around bug
# 5057552, which is actually caused by lax privileges defined by 
# /etc/security/console.perms
MINDISP=11              # minimum display number XXX
MAXDISP=1000            # maximum display number XXX -> must match OWconfig

cleanup() {
  /bin/mkdir -p $CONFIGXDIR

  for src 
  do
    tsrc=$CONFIGXDIR/$src

    #
    # Make the empty file
    #
    /bin/rm -f $tsrc
    /bin/touch $tsrc
  done

  return 0
}

cleanup Xconfig Xservers

#
# if gdm is running cleanup displays
#

pgrep -P 1 -u 0 $DMNAME >/dev/null
if [[ $? -eq 0 ]]
then
	dpys=`/usr/bin/gdmdynamic -l`
	for dpy in $dpys
	do
          if [[ $dpy -ge $MINDISP && $dpy -le $MAXDISP ]]; then
            /usr/bin/gdmdynamic -d $dpy >/dev/null
          fi
	done
fi

exit 0
