Leser: 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
#!/usr/bin/perl $|++; use strict; use warnings; use diagnostics; use CGI::Carp qw(fatalsToBrowser); use CGI; use Fcntl qw(:flock); use File::Spec; my $log_file = File::Spec->catfile($ENV{'DOCUMENT_ROOT'},'logs','sig_test.txt'); $SIG{'PIPE'} = 'IGNORE'; $SIG{'TERM'} = \&sig_handler; my $handling_request = 1; my $query = new CGI; print $query->header('-type' => 'text/html; charset=iso-8859-1'); print $query->start_html(); foreach my $step(0..5){ print $query->br($step); sleep 1; } print $query->end_html(); &log_it("Script finished"); $handling_request = 0; sub log_it{ my $text = shift; open(LOG, ">> $log_file") or die("open(LOG, >> $log_file) failed $!"); flock(LOG, LOCK_EX); print LOG scalar(localtime) . ' ' . $text . "\n"; close(LOG) or die("close(LOG) failed $!"); return; } sub sig_handler(){ if($handling_request){ &log_it("Script broken"); exit; } }