# HG changeset patch # User Heiko Schlittermann # Date 1233088135 -3600 # Node ID a00ff9ea5ad6c788d4051b14c756c0cb5b245fce # Parent c49b149103943afb63effb6151f21104836f7a3a Fixed port-Bug. diff -r c49b14910394 -r a00ff9ea5ad6 hlog --- a/hlog Tue Jan 27 20:50:54 2009 +0100 +++ b/hlog Tue Jan 27 21:28:55 2009 +0100 @@ -31,14 +31,14 @@ sub handle_request($); sub date1123(;$); -sub http($$); +sub http($@); sub bad_request(); MAIN: { GetOptions( - "addr" => \$opt_addr, - "port" => \$opt_port, + "addr=s" => \$opt_addr, + "port=i" => \$opt_port, ) or pod2usage(); open(LOG, ">>$logfile"); @@ -49,7 +49,6 @@ my $listener = new IO::Socket::INET( LocalAddr => $opt_addr, LocalPort => $opt_port, - Port => $opt_port, Proto => "tcp", Listen => 1, ReuseAddr => 1, @@ -58,11 +57,13 @@ warn "listener $opt_addr:$opt_port\n"; while (my $client = $listener->accept) { - print LOG localtime() + print LOG $_ = localtime() . " access from " . $client->peerhost . ":" . $client->peerport . "\n"; + warn $_; + my $pid = fork(); die "Can't fork: $!\n" if not defined $pid; if ($pid == 0) { @@ -91,27 +92,30 @@ } open(my $file, $FILE); - $client->print(http "200 OK" => join "", - "# Proof of concept ;-)\n", - "# see https://keller.schlittermann.de/hg/hlog\n", - <$file>); + + $client->print(http "200 OK" => join "", <<__EOF, <$file>); +# Proof of concept ;-) +# see https://keller.schlittermann.de/hg/hlog +# +# FILE: $FILE +# +__EOF } -sub http($$) { - my ($code, $msg) = @_; +sub http($@) { + my $code = shift; my $date = date1123(); - my $type = $msg =~ /^ 400 Bad Request @@ -134,7 +138,7 @@ />

-EOF +__EOF } __END__