--- loncom/lond 2001/11/26 20:31:01 1.57 +++ loncom/lond 2001/11/27 21:59:07 1.59 @@ -17,9 +17,9 @@ # 04/02 Scott Harrison # 05/11,05/28,08/30 Gerd Kortemeyer # 9/30,10/22,11/13,11/15,11/16 Scott Harrison -# 11/26 Gerd Kortemeyer +# 11/26,11/27 Gerd Kortemeyer # -# $Id: lond,v 1.57 2001/11/26 20:31:01 www Exp $ +# $Id: lond,v 1.59 2001/11/27 21:59:07 www Exp $ ### # based on "Perl Cookbook" ISBN 1-56592-243-3 @@ -53,6 +53,7 @@ sub catchexception { ."a crash with this error msg->[$error]"); &logthis('Famous last words: '.$status.' - '.$lastlog); if ($client) { print $client "error: $error\n"; } + $server->close(); die($error); } @@ -138,6 +139,7 @@ sub REAPER { # ta sub HUNTSMAN { # signal handler for SIGINT local($SIG{CHLD}) = 'IGNORE'; # we're going to kill our children kill 'INT' => keys %children; + &logthis("Free socket: ".shutdown($server,2)); # free up socket my $execdir=$perlvar{'lonDaemons'}; unlink("$execdir/logs/lond.pid"); &logthis("CRITICAL: Shutting down"); @@ -147,7 +149,7 @@ sub HUNTSMAN { # si sub HUPSMAN { # signal handler for SIGHUP local($SIG{CHLD}) = 'IGNORE'; # we're going to kill our children kill 'INT' => keys %children; - close($server); # free up socket + &logthis("Free socket: ".shutdown($server,2)); # free up socket &logthis("CRITICAL: Restarting"); unlink("$execdir/logs/lond.pid"); my $execdir=$perlvar{'lonDaemons'}; @@ -175,6 +177,7 @@ sub logthis { my $fh=IO::File->new(">>$execdir/logs/lond.log"); my $now=time; my $local=localtime($now); + $lastlog=$local.': '.$message; print $fh "$local ($$): $message\n"; } @@ -445,20 +448,17 @@ sub make_new_child { } else { &logthis( "WARNING: $clientip did not reply challenge"); - print $client "bye\n"; &status('No challenge reply '.$clientip); } } else { &logthis( "WARNING: " ."$clientip failed to initialize: >$remotereq< "); - print $client "bye\n"; &status('No init '.$clientip); } } else { &logthis( "WARNING: Unknown client $clientip"); - print $client "bye\n"; &status('Hung up on '.$clientip); } if ($clientok) { @@ -466,7 +466,7 @@ sub make_new_child { &reconlonc("$perlvar{'lonSockDir'}/$hostid{$clientip}"); &logthis( "Established connection: $hostid{$clientip}"); - &status('Listening to '.$hostid{$clientip}); + &status('Will listen to '.$hostid{$clientip}); # ------------------------------------------------------------ Process requests while (my $userinput=<$client>) { chomp($userinput); @@ -1293,16 +1293,20 @@ sub make_new_child { &logthis( "Client $clientip ($hostid{$clientip}) hanging up: $userinput"); print $client "bye\n"; + $client->close(); last; # ------------------------------------------------------------- unknown command } else { # unknown command print $client "unknown_cmd\n"; } -# ------------------------------------------------------ client unknown, refuse +# -------------------------------------------------------------------- complete + &status('Listening to '.$hostid{$clientip}); } +# --------------------------------------------- client unknown or fishy, refuse } else { print $client "refused\n"; + $client->close(); &logthis("WARNING: " ."Rejected client $clientip, closing connection"); } @@ -1313,6 +1317,9 @@ sub make_new_child { # tidy up gracefully and finish + $client->close(); + $server->close(); + # this exit is VERY important, otherwise the child will become # a producer of more and more children, forking yourself into # process death.