#!/bin/sh
#Exit from X, will cause return to xwin.

#/sbin/pup_event_frontend_d will quit if this file exists...
echo -n "exit" > /tmp/wmexitmode.txt

#give time for /sbin/pup_event_frontend_d to quit.
#w478 testing 2.6.18.1 kernel, pup_event_frontend_d did not exit when it
#detected /tmp/wmeximode.txt, but became 'defunct'...
KCNT=0
PSPEFD="`ps -C pup_event_frontend_d | grep 'pup_event_front' | grep -v 'defunct'`"
#while [ "`pidof pup_event_frontend_d`" != "" ];do
while [ "$PSPEFD" != "" ];do
 sleep 0.5
 KCNT=`expr $KCNT + 1`
 [ $KCNT -gt 60 ] && break #30 secs.
 PSPEFD="`ps -C pup_event_frontend_d | grep 'pup_event_front' | grep -v 'defunct'`"
done
sleep 0.2

sync

if [ "`pidof xfce4-panel`" != "" ];then
 #killall xfce4-panel
 kill `pidof xfce4-panel`
 exit
fi

#w003
CURRENTWM="`cat /etc/windowmanager`"
kill -9 `pidof $CURRENTWM`

##exec killall $PREVIOUSWM
##exec killall X
#killall X #default is SIGTERM.
#sleep 1
#exec killall -9 X #make sure X is killed.
