#!/opt/csw/bin/perl
use IPC::SysV qw(IPC_PRIVATE S_IRWXU IPC_CREAT);
use IPC::Semaphore;

use constant NFSCHECKSEMKEY => 8;
#use constant FILE => '/home/system/www/home/today/index.shtml';
use constant FILE => '/etc/passwd';

$sem = new IPC::Semaphore(NFSCHECKSEMKEY , 1, S_IRWXU | IPC_CREAT) || die "Can't create semaphore! $!";

if (($pid = $sem->getval(0)) != 0) {
	if (kill(0, $pid)==1) {
		print "erp! Already checking - pid $pid\n";
		exit 1;
	} else {
		print "erp! Went away - starting another\n";
		$sem->setall($$);
	}
}

##  set a semaphore lock, so we don't kick off too many processes
$sem->setall($$);

## stat file, make sure NFS still works.
if (! (stat(FILE))[1] ) {
	print "Some tard's unmounted the filesystem?"
}

$sem->setall(0);
exit 0;
