--- loncom/lond 2003/01/13 21:52:11 1.105
+++ loncom/lond 2003/01/15 04:43:14 1.106
@@ -2,7 +2,7 @@
# The LearningOnline Network
# lond "LON Daemon" Server (port "LOND" 5663)
#
-# $Id: lond,v 1.105 2003/01/13 21:52:11 matthew Exp $
+# $Id: lond,v 1.106 2003/01/15 04:43:14 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -54,13 +54,13 @@
# 02/19 Matthew Hall
# 02/25 Gerd Kortemeyer
# 05/11 Scott Harrison
+# 01/xx/2003 Ron Fox.. Remove preforking. This makes the general daemon
+# logic simpler (and there were problems maintaining the preforked
+# population). Since the time averaged connection rate is close to zero
+# because lonc's purpose is to maintain near continuous connnections,
+# preforking is not really needed.
###
-# based on "Perl Cookbook" ISBN 1-56592-243-3
-# preforker - server who forks first
-# runs as a daemon
-# HUPs
-# uses IDEA encryption
use lib '/home/httpd/lib/perl/';
use LONCAPA::Configuration;
@@ -491,37 +491,35 @@ close(PIDSAVE);
&logthis("CRITICAL: ---------- Starting ----------");
&status('Starting');
-# ------------------------------------------------------- Now we are on our own
-
-# Fork off our children.
-for (1 .. $PREFORK) {
- make_new_child();
-}
+
# ----------------------------------------------------- Install signal handlers
-&status('Forked children');
$SIG{CHLD} = \&REAPER;
$SIG{INT} = $SIG{TERM} = \&HUNTSMAN;
$SIG{HUP} = \&HUPSMAN;
$SIG{USR1} = \&checkchildren;
-# And maintain the population.
+
+
+# --------------------------------------------------------------
+# Accept connections. When a connection comes in, it is validated
+# and if good, a child process is created to process transactions
+# along the connection.
+
while (1) {
- &status('Sleeping');
- sleep; # wait for a signal (i.e., child's death)
- &logthis('Woke up');
- &status('Woke up');
- for ($i = $children; $i < $PREFORK; $i++) {
- make_new_child(); # top up the child pool
- }
+ $client = $server->accept() or next;
+ make_new_child($client);
}
sub make_new_child {
+ my $client;
my $pid;
my $cipher;
my $sigset;
+
+ $client = shift;
&logthis("Attempting to start child");
# block signal for fork
$sigset = POSIX::SigSet->new(SIGINT);
@@ -555,10 +553,6 @@ sub make_new_child {
&Authen::Krb5::init_context();
&Authen::Krb5::init_ets();
- # handle connections until we've reached $MAX_CLIENTS_PER_CHILD
- for ($i=0; $i < $MAX_CLIENTS_PER_CHILD; $i++) {
- &status('Idle, waiting for connection');
- $client = $server->accept() or last;
&status('Accepted connection');
# =============================================================================
# do something with the connection
@@ -566,7 +560,7 @@ sub make_new_child {
$client->sockopt(SO_KEEPALIVE, 1);# Enable monitoring of
# connection liveness.
# see if we know client and check for spoof IP by challenge
- my $caller=getpeername($client);
+ my $caller = getpeername($client);
my ($port,$iaddr)=unpack_sockaddr_in($caller);
my $clientip=inet_ntoa($iaddr);
my $clientrec=($hostid{$clientip} ne undef);
@@ -1546,21 +1540,19 @@ sub make_new_child {
&logthis("WARNING: "
."Rejected client $clientip, closing connection");
}
- }
+ }
# =============================================================================
&logthis("CRITICAL: "
."Disconnect from $clientip ($hostid{$clientip})");
- # tidy up gracefully and finish
-
- $server->close();
+
# this exit is VERY important, otherwise the child will become
# a producer of more and more children, forking yourself into
# process death.
exit;
- }
+
}