Diff for /loncom/loncnew between versions 1.26 and 1.27

version 1.26, 2003/09/30 11:11:17 version 1.27, 2003/10/07 11:23:03
Line 45 Line 45
   
 # Change log:  # Change log:
 #    $Log$  #    $Log$
   #    Revision 1.27  2003/10/07 11:23:03  foxr
   #    Installed and tested code to process reinit in parent server.
   #
 #    Revision 1.26  2003/09/30 11:11:17  foxr  #    Revision 1.26  2003/09/30 11:11:17  foxr
 #    Add book-keeping hashes to support the re-init procedure.  #    Add book-keeping hashes to support the re-init procedure.
 #  #
Line 1524  sub CreateChild { Line 1527  sub CreateChild {
     my $pid          = fork;      my $pid          = fork;
     if($pid) { # Parent      if($pid) { # Parent
  $RemoteHost = "Parent";   $RemoteHost = "Parent";
  $ChildHash{$pid} = $RemoteHost;   $ChildHash{$pid} = $host;
  $HostToPid{$host}= $pid;   $HostToPid{$host}= $pid;
  sigprocmask(SIG_UNBLOCK, $sigset);   sigprocmask(SIG_UNBLOCK, $sigset);
   
Line 1664  Kills off (via sigint) children for host Line 1667  Kills off (via sigint) children for host
   
 =item  =item
   
 HUP's children for hosts that already exist (this just forces a status display  QUITs  children for hosts that already exist (this just forces a status display
 and resets the connection retry count for that host.  and resets the connection retry count for that host.
   
 =item  =item
Line 1675  the start of the master program and main Line 1678  the start of the master program and main
 =cut  =cut
   
 sub UpdateKids {  sub UpdateKids {
   
     Log("INFO", "Updating connections via SIGUSR2");      Log("INFO", "Updating connections via SIGUSR2");
   
       #  Just in case we need to kill our own lonc, we wait a few seconds to
       #  give it a chance to receive and relay lond's response to the 
       #  re-init command.
       #
   
       sleep(2); # Wait a couple of seconds.
   
       my %hosts;                   # Indexed by loncapa hostname, value=ip.
       
       # Need to re-read  the host table:
       
       
       LondConnection::ReadConfig();
       my $I = LondConnection::GetHostIterator;
       while (! $I->end()) {
    my $item = $I->get();
    $hosts{$item->[0]} = $item->[4];
    $I->next();
       }
   
       #  The logic below is written for clarity not for efficiency.
       #  Since I anticipate that this function is only rarely called, that's
       #  appropriate.  There are certainly ways to combine the loops below,
       #  and anyone wishing to obscure the logic is welcome to go for it.
       #  Note that we don't re-direct sigchild.  Instead we do what's needed
       #  to the data structures that keep track of children to ensure that
       #  when sigchild is honored, no new child is born.
       #
   
       #  For each existing child; if it's host doesn't exist, kill the child.
   
       foreach my $child (keys %ChildHash) {
    my $oldhost = $ChildHash{$child};
    if (!(exists $hosts{$oldhost})) {
       Log("CRITICAL", "Killing child for $oldhost  host no longer exists");
       delete $ChildHash{$child};
       delete $HostToPid{$oldhost};
       kill 'QUIT' => $child;
    }
       }
       # For each remaining existing child; if it's host's ip has changed,
       # Restart the child on the new IP.
   
       foreach my $child (keys %ChildHash) {
    my $oldhost = $ChildHash{$child};
    my $oldip   = $HostHash{$oldhost};
    if ($hosts{$oldhost} ne $oldip) {
   
       # kill the old child.
   
       Log("CRITICAL", "Killing child for $oldhost host ip has changed...");
       delete $ChildHash{$child};
       delete $HostToPid{$oldhost};
       kill 'QUIT' => $child;
   
       # Do the book-keeping needed to start a new child on the
       # new ip.
   
       $HostHash{$oldhost} = $hosts{$oldhost};
       CreateChild($oldhost);
    }
       }
       # Finally, for each new host, not in the host hash, create a
       # enter the host and create a new child.
       # Force a status display of any existing process.
   
       foreach my $host (keys %hosts) {
    if(!(exists $HostHash{$host})) {
       Log("INFO", "New host $host discovered in hosts.tab...");
       $HostHash{$host} = $hosts{$host};
       CreateChild($host);
    } else {
       kill 'HUP' => $HostToPid{$host};    # status display.
    }
       }
 }  }
   
   

Removed from v.1.26  
changed lines
  Added in v.1.27


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