| 1 |
root |
1.1 |
#!/usr/bin/perl |
| 2 |
|
|
$crossname = "/madhatter/bin/crossfire"; |
| 3 |
|
|
$playerdir = "/madhatter/lib/X11/crossfire/players"; |
| 4 |
|
|
$logcount = 0; |
| 5 |
|
|
$logdir= "/tmp/crosslog"; |
| 6 |
|
|
|
| 7 |
|
|
if (! -d $logdir) { |
| 8 |
|
|
mkdir($logdir,0775) || die("Unable to mkdir $logdir\n"); |
| 9 |
|
|
} |
| 10 |
|
|
system("rm $logdir/*"); |
| 11 |
|
|
|
| 12 |
|
|
$badcount = 0; |
| 13 |
|
|
while(1) { |
| 14 |
|
|
++$logcount; |
| 15 |
|
|
$starttime = time; |
| 16 |
|
|
&doserver; |
| 17 |
|
|
system("rm /tmp/*$crosspid.o?"); |
| 18 |
|
|
system("rmdir $playerdir/*.lock"); |
| 19 |
|
|
$badcount = 0 if ((time-$startime)<300); |
| 20 |
|
|
++$badcount; |
| 21 |
|
|
die("Crossfire really unhappy\n") |
| 22 |
|
|
if $badcount>10; |
| 23 |
|
|
} |
| 24 |
|
|
|
| 25 |
|
|
sub doserver { |
| 26 |
|
|
open(LOGFILE,">$logdir/$logcount") |
| 27 |
|
|
|| die("Unable to open $logdir/$logcount for write\n"); |
| 28 |
|
|
$oldfh = select(LOGFILE);$|=1;select(LOGFILE); |
| 29 |
|
|
pipe(READ,WRITE); |
| 30 |
|
|
if (($crosspid=fork)>0) { |
| 31 |
|
|
# Parent |
| 32 |
|
|
close(WRITE); |
| 33 |
|
|
$now = time; |
| 34 |
|
|
$toomuch =0; |
| 35 |
|
|
while(<READ>) { |
| 36 |
|
|
if ((time-$now)<5) { |
| 37 |
|
|
++$toomuch; |
| 38 |
|
|
if ($toomuch>500) { |
| 39 |
|
|
print LOGFILE "Crossfire Talks too much\n"; |
| 40 |
|
|
kill 'HUP', $crosspid; |
| 41 |
|
|
sleep(5); |
| 42 |
|
|
kill 'TERM', $crosspid; |
| 43 |
|
|
sleep(5); |
| 44 |
|
|
kill 'INT', $crosspid; |
| 45 |
|
|
sleep(5); |
| 46 |
|
|
kill 9, $crosspid; |
| 47 |
|
|
last; |
| 48 |
|
|
} |
| 49 |
|
|
} else { |
| 50 |
|
|
$toomuch = 0; |
| 51 |
|
|
} |
| 52 |
|
|
print LOGFILE $_; |
| 53 |
|
|
} |
| 54 |
|
|
} elsif ($crosspid==0) { |
| 55 |
|
|
close(READ); |
| 56 |
|
|
open(STDOUT,">&WRITE") || die("Can't redirect stdout\n"); |
| 57 |
|
|
open(STDERR,">&WRITE") || die("Can't redirect stderr\n"); |
| 58 |
|
|
exec "$crossname","-server"; |
| 59 |
|
|
die("Exec Failed\n"); |
| 60 |
|
|
} else { |
| 61 |
|
|
die("can't fork\n"); |
| 62 |
|
|
} |
| 63 |
|
|
close(LOGFILE); |
| 64 |
|
|
} |