#!/bin/sh
#remove stale pid files
if [ -e /var/run/xinetd.pid ]
then
	mypids="`cat /var/run/xinetd.pid`"
	myrun=`/sbin/pidof xinetd`
	ok=0
	for x in $mypids
	do
		if [ "$myrun" = "$x" ]
		then
			#this is a running xinetd process, pidfile ok
			ok=1
		fi
	done
	if [ "$ok" = "0" ]
	then
		#bogus pidfile, remove
		rm /var/run/xinetd.pid
	fi
else
	/usr/sbin/xinetd -pidfile /var/run/xinetd.pid
	/usr/bin/sleep 1
fi
exec /usr/bin/watchpid `cat /var/run/xinetd.pid`
