[LON-CAPA-cvs] cvs: modules /gerd lonhttpd

www lon-capa-cvs@mail.lon-capa.org
Tue, 29 Oct 2002 19:23:02 -0000


www		Tue Oct 29 14:23:02 2002 EDT

  Modified files:              
    /modules/gerd	lonhttpd 
  Log:
  Start forking.
  
  
Index: modules/gerd/lonhttpd
diff -u modules/gerd/lonhttpd:1.1 modules/gerd/lonhttpd:1.2
--- modules/gerd/lonhttpd:1.1	Tue Oct 29 13:54:02 2002
+++ modules/gerd/lonhttpd	Tue Oct 29 14:23:02 2002
@@ -1,12 +1,22 @@
 #!/usr/bin/perl
 # TinyHTTPD - a minimum-functional HTTP server written in -*- Perl -*-
 # -ot.0894
-# $Id: lonhttpd,v 1.1 2002/10/29 18:54:02 www Exp $
+# $Id: lonhttpd,v 1.2 2002/10/29 19:23:02 www Exp $
 
 # Currently supported: HTTP 1.0/1.1 GET and POST queries
 # File types of .html and .gif
 
-$ENV{'SERVER_SOFTWARE'}="TinyHTTPD $Revision: 1.1 $ -ot.0894 (LON-CAPA)";
+$ENV{'SERVER_SOFTWARE'}="TinyHTTPD $Revision: 1.2 $ -ot.0894 (LON-CAPA)";
+
+
+use POSIX qw(:sys_wait_h);
+
+sub REAPER {
+    1 until (-1==waitpid(-1,WNOHANG));
+    $SIG{CHLD}=\&REAPER;
+}
+
+$SIG{CHLD}=\&REAPER;
 
 ## Configuration section
 $port=8080;			# Port on which we listen
@@ -48,6 +58,9 @@
 # accept incoming calls
 for (;;) {
     ($addr=accept(NS,S)) || die "accept: $!";
+    next if $pid=fork;
+    die "fork: $!" unless defined $pid;
+    close(S);
     ($a,$p,$inetaddr) = unpack($sockaddr, $addr);
     @inetaddr = unpack('C4', $inetaddr);
     ($host,$aliases) = gethostbyaddr($inetaddr, $AF_INET);
@@ -55,12 +68,12 @@
     @host=split(' ', "$host $aliases");
     $host || do { $host = $inetaddr; };
     @t=localtime;
-    print LOG "** @t[1..5]: $$ connect from $host ($inetaddr)\n";
     open(STDIN, "+<&NS") || die "dup2 ns->stdin";
     open(STDOUT, "+>&NS") || die "dup2 ns->stdout";
     select(STDOUT); $|=1;
     &serve_request;
     close(STDIN); close(STDOUT);
+    exit;
 }
 
 # Read request from stdin and produce output
@@ -81,7 +94,6 @@
     }
     ($method=~/^(GET|POST)$/) || do { &error(501,$method); return; };
 
-    print LOG "$$ Request: $method $url\n";
     # prevent directory go-back
     $url=~/\.\./ && do { &error(403,$url,"contains go-back"); return; };