Diff for /loncom/lond between versions 1.146 and 1.148

version 1.146, 2003/09/16 10:28:14 version 1.148, 2003/09/29 10:09:18
Line 60 Line 60
 # 09/08/2003 Ron Fox:  Told lond to take care of change logging so we  # 09/08/2003 Ron Fox:  Told lond to take care of change logging so we
 #      don't have to remember it:  #      don't have to remember it:
 # $Log$  # $Log$
   # Revision 1.148  2003/09/29 10:09:18  foxr
   # Put in logic to reinit lond itself (except for apache reload).  I don't believe
   # this logic works correctly yet, however lond still does everything it used to doso I'll do the commit anyway.
   #
   # Revision 1.147  2003/09/23 11:23:31  foxr
   # Comlplete implementation of reinit functionality.  Must still implement
   # the actual initialization functionality, but the process can now
   # receive the request and either invoke the appropriate internal function or
   # signal the correct lonc.
   #
 # Revision 1.146  2003/09/16 10:28:14  foxr  # Revision 1.146  2003/09/16 10:28:14  foxr
 # ReinitProcess - decode the process selector and produce the associated pid  # ReinitProcess - decode the process selector and produce the associated pid
 # filename.  Note: While it is possible to test that valid process selectors are  # filename.  Note: While it is possible to test that valid process selectors are
Line 388  sub ReinitProcess { Line 398  sub ReinitProcess {
     #      #
     #      #
     my ($junk, $process) = split(":", $request);      my ($junk, $process) = split(":", $request);
     my $processpidfile = $perlvar{'lonDaemons'}.'/';      my $processpidfile = $perlvar{'lonDaemons'}.'/logs/';
     if($process eq 'lonc') {      if($process eq 'lonc') {
  $processpidfile = $processpidfile."lonc.pid";   $processpidfile = $processpidfile."lonc.pid";
    if (!open(PIDFILE, "< $processpidfile")) {
       return "error:Open failed for $processpidfile";
    }
    my $loncpid = <PIDFILE>;
    close(PIDFILE);
    logthis('<font color="red"> Reinitializing lonc pid='.$loncpid
    ."</font>");
    kill("USR2", $loncpid);
     } elsif ($process eq 'lond') {      } elsif ($process eq 'lond') {
  $processpidfile = $processpidfile."lond.pid";   logthis('<font color="red"> Reinitializing self (lond) </font>');
    &UpdateHosts; # Lond is us!!
     } else {      } else {
  &logthis('<font color="yellow" Invalid reinit request for '.$process   &logthis('<font color="yellow" Invalid reinit request for '.$process
  ."</font>");   ."</font>");
  return "error:Invalid process identifier $process";   return "error:Invalid process identifier $process";
     }      }
     &logthis('<font color="red"> Reinitializing '.$process." </font>");  
     return 'ok';      return 'ok';
 }  }
   
Line 478  if (-e $pidfile) { Line 496  if (-e $pidfile) {
   
 # ------------------------------------------------------------- Read hosts file  # ------------------------------------------------------------- Read hosts file
   
 open (CONFIG,"$perlvar{'lonTabDir'}/hosts.tab") || die "Can't read host file";  
   
 while (my $configline=<CONFIG>) {  
     my ($id,$domain,$role,$name,$ip)=split(/:/,$configline);  
     chomp($ip); $ip=~s/\D+$//;  
     $hostid{$ip}=$id;  
     $hostdom{$id}=$domain;  
     $hostip{$id}=$ip;  
     if ($id eq $perlvar{'lonHostID'}) { $thisserver=$name; }  
 }  
 close(CONFIG);  
   
 # establish SERVER socket, bind and listen.  # establish SERVER socket, bind and listen.
 $server = IO::Socket::INET->new(LocalPort => $perlvar{'londPort'},  $server = IO::Socket::INET->new(LocalPort => $perlvar{'londPort'},
Line 538  sub HUPSMAN {                      # sig Line 546  sub HUPSMAN {                      # sig
 }  }
   
 #  #
   #    Kill off hashes that describe the host table prior to re-reading it.
   #    Hashes affected are:
   #       %hostid, %hostdom %hostip
   #
   sub KillHostHashes {
       foreach my $key (keys %hostid) {
    delete $hostid{$key};
       }
       foreach my $key (keys %hostdom) {
    delete $hostdom{$key};
       }
       foreach my $key (keys %hostip) {
    delete $hostip{$key};
       }
   }
   #
   #   Read in the host table from file and distribute it into the various hashes:
   #
   #    - %hostid  -  Indexed by IP, the loncapa hostname.
   #    - %hostdom -  Indexed by  loncapa hostname, the domain.
   #    - %hostip  -  Indexed by hostid, the Ip address of the host.
   sub ReadHostTable {
   
       open (CONFIG,"$perlvar{'lonTabDir'}/hosts.tab") || die "Can't read host file";
       
       while (my $configline=<CONFIG>) {
    my ($id,$domain,$role,$name,$ip)=split(/:/,$configline);
    chomp($ip); $ip=~s/\D+$//;
    $hostid{$ip}=$id;
    $hostdom{$id}=$domain;
    $hostip{$id}=$ip;
    if ($id eq $perlvar{'lonHostID'}) { $thisserver=$name; }
       }
       close(CONFIG);
   }
   #
   #  Reload the Apache daemon's state.
   #
   sub ReloadApache {
   }
   
   #
 #   Called in response to a USR2 signal.  #   Called in response to a USR2 signal.
 #   - Reread hosts.tab  #   - Reread hosts.tab
 #   - All children connected to hosts that were removed from hosts.tab  #   - All children connected to hosts that were removed from hosts.tab
Line 548  sub HUPSMAN {                      # sig Line 598  sub HUPSMAN {                      # sig
 #     now be honored.  #     now be honored.
 #  #
 sub UpdateHosts {  sub UpdateHosts {
       logthis('<font color="blue"> Updating connections </font>');
       #
       #  The %children hash has the set of IP's we currently have children
       #  on.  These need to be matched against records in the hosts.tab
       #  Any ip's no longer in the table get killed off they correspond to
       #  either dropped or changed hosts.  Note that the re-read of the table
       #  will take care of new and changed hosts as connections come into being.
   
   
       KillHostHashes;
       ReadHostTable;
   
       foreach my $child (keys %children) {
    my $childip = $children{$child};
    if(!$hostid{$childip}) {
       kill('INT', $child);
    }
       }
       ReloadApache;
 }  }
   
   
 sub checkchildren {  sub checkchildren {
     &initnewstatus();      &initnewstatus();
     &logstatus();      &logstatus();
Line 794  $SIG{HUP}  = \&HUPSMAN; Line 864  $SIG{HUP}  = \&HUPSMAN;
 $SIG{USR1} = \&checkchildren;  $SIG{USR1} = \&checkchildren;
 $SIG{USR2} = \&UpdateHosts;  $SIG{USR2} = \&UpdateHosts;
   
   #  Read the host hashes:
   
   ReadHostTable;
   
 # --------------------------------------------------------------  # --------------------------------------------------------------
 #   Accept connections.  When a connection comes in, it is validated  #   Accept connections.  When a connection comes in, it is validated
Line 818  sub make_new_child { Line 891  sub make_new_child {
         or die "Can't block SIGINT for fork: $!\n";          or die "Can't block SIGINT for fork: $!\n";
   
     die "fork: $!" unless defined ($pid = fork);      die "fork: $!" unless defined ($pid = fork);
   
       $client->sockopt(SO_KEEPALIVE, 1); # Enable monitoring of
                                  # connection liveness.
   
       #
       #  Figure out who we're talking to so we can record the peer in 
       #  the pid hash.
       #
       my $caller = getpeername($client);
       my ($port,$iaddr)=unpack_sockaddr_in($caller);
       $clientip=inet_ntoa($iaddr);
           
     if ($pid) {      if ($pid) {
         # Parent records the child's birth and returns.          # Parent records the child's birth and returns.
         sigprocmask(SIG_UNBLOCK, $sigset)          sigprocmask(SIG_UNBLOCK, $sigset)
             or die "Can't unblock SIGINT for fork: $!\n";              or die "Can't unblock SIGINT for fork: $!\n";
         $children{$pid} = 1;          $children{$pid} = $clientip;
         $children++;          $children++;
         &status('Started child '.$pid);          &status('Started child '.$pid);
         return;          return;
Line 850  sub make_new_child { Line 934  sub make_new_child {
 # =============================================================================  # =============================================================================
             # do something with the connection              # do something with the connection
 # -----------------------------------------------------------------------------  # -----------------------------------------------------------------------------
     $client->sockopt(SO_KEEPALIVE, 1);# Enable monitoring of   # see if we know client and check for spoof IP by challenge
                                       # connection liveness.  
             # see if we know client and check for spoof IP by challenge  
  my $caller = getpeername($client);  
             my ($port,$iaddr)=unpack_sockaddr_in($caller);  
             $clientip=inet_ntoa($iaddr);  
             my $clientrec=($hostid{$clientip} ne undef);              my $clientrec=($hostid{$clientip} ne undef);
             &logthis(              &logthis(
 "<font color=yellow>INFO: Connection, $clientip ($hostid{$clientip})</font>"  "<font color=yellow>INFO: Connection, $clientip ($hostid{$clientip})</font>"

Removed from v.1.146  
changed lines
  Added in v.1.148


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>