--- loncom/lond 2001/11/26 20:59:01 1.58 +++ 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.58 2001/11/26 20:59: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'}; @@ -446,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) { @@ -1294,6 +1293,7 @@ sub make_new_child { &logthis( "Client $clientip ($hostid{$clientip}) hanging up: $userinput"); print $client "bye\n"; + $client->close(); last; # ------------------------------------------------------------- unknown command } else { @@ -1303,9 +1303,10 @@ sub make_new_child { # -------------------------------------------------------------------- complete &status('Listening to '.$hostid{$clientip}); } -# ------------------------------------------------------ client unknown, refuse +# --------------------------------------------- client unknown or fishy, refuse } else { print $client "refused\n"; + $client->close(); &logthis("WARNING: " ."Rejected client $clientip, closing connection"); } @@ -1316,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.