#!/bin/csh -f
#
# Monitor the xcrash program
#

set xisup = "no"
set count = "0"
if (-e crash.count) set count = "`cat crash.count`"
while (1)
	if ("$xisup" == "no") then
		rm -f core
		X :0 & ; sleep 2 ; xset s off &
		set xisup = "yes"
	endif
	@ count++
	echo "$count" > crash.count
	./xcrash -v -q -tests 40 > xcrash.log ; sleep 1
	# $status will be <>0 when there is a crash
	if (-e /usr/bin/X11/Xsun) then
		set xpid = "`ps -aux|grep -v grep|grep X|cut -c11-14`" #Sun
	else
		set xpid = "`ps -e|grep -v grep|grep X|cut -c1-6`"     #RS6000
	endif
	if ("$xpid" == "") then
		if (-e /usr/bin/X11/kbd_mode) kbd_mode -a
		echo "X has crashed"
		mv xcrash.log crash.$count
		set xisup = "no"
		if (-e core) then
			sleep 15 ; # wait for full core
			echo "where"| dbx /usr/bin/X11/X >> crash.$count
		endif
	endif
end
