Diff for /loncom/loncnew between versions 1.80 and 1.81

version 1.80, 2007/03/28 00:23:46 version 1.81, 2007/03/28 20:28:29
Line 60  use LONCAPA::Stack; Line 60  use LONCAPA::Stack;
 use LONCAPA::LondConnection;  use LONCAPA::LondConnection;
 use LONCAPA::LondTransaction;  use LONCAPA::LondTransaction;
 use LONCAPA::Configuration;  use LONCAPA::Configuration;
 use LONCAPA::HashIterator;  
 use Fcntl qw(:flock);  use Fcntl qw(:flock);
   
   
Line 94  my $executable      = $0; # Get the full Line 93  my $executable      = $0; # Get the full
 #  The variables below are only used by the child processes.  #  The variables below are only used by the child processes.
 #  #
 my $RemoteHost; # Name of host child is talking to.  my $RemoteHost; # Name of host child is talking to.
   my $RemoteHostId; # default lonid of host child is talking to.
 my $UnixSocketDir= $perlvar{'lonSockDir'};  my $UnixSocketDir= $perlvar{'lonSockDir'};
 my $IdleConnections = Stack->new(); # Set of idle connections  my $IdleConnections = Stack->new(); # Set of idle connections
 my %ActiveConnections; # Connections to the remote lond.  my %ActiveConnections; # Connections to the remote lond.
Line 112  my $LondConnecting  = 0;       # True wh Line 112  my $LondConnecting  = 0;       # True wh
   
   
   
 my $hosts_tab       = 0;        # True if we are using a static hosts.tab  
 my $I_am_child      = 0; # True if this is the child process.  my $I_am_child      = 0; # True if this is the child process.
   
 #  #
Line 333  sub child_exit { Line 332  sub child_exit {
     open(LOCK,">$lock_file");      open(LOCK,">$lock_file");
     print LOCK "Contents not important";      print LOCK "Contents not important";
     close(LOCK);      close(LOCK);
     if ($hosts_tab) {      unlink(&GetLoncSocketPath());
  unlink(&GetLoncSocketPath());  
     }  
   
     if ($message) {      if ($message) {
  die($message);   die($message);
Line 1150  sub LondWritable { Line 1147  sub LondWritable {
     }      }
           
 }  }
   
 =pod  =pod
           
 =cut  =cut
   
   
 sub QueueDelayed {  sub QueueDelayed {
     Debug(3,"QueueDelayed called");      Debug(3,"QueueDelayed called");
   
Line 1162  sub QueueDelayed { Line 1161  sub QueueDelayed {
     Debug(4, "Delayed path: ".$path);      Debug(4, "Delayed path: ".$path);
     opendir(DIRHANDLE, $path);      opendir(DIRHANDLE, $path);
   
     my @all_host_ids;      use Apache::lonnet;
     my $host_iterator =   &LondConnection::GetHostIterator();      my @all_host_ids = &Apache::lonnet::machine_ids($RemoteHost);
     while (!$host_iterator->end()) {  
  my ($host_id,$host_name) = @{$host_iterator->get()}[0,3];  
  if ($host_name eq $RemoteHost) {  
     push(@all_host_ids, $host_id);  
  }  
  $host_iterator->next();  
     }  
     my $host_id_re = '(?:'.join('|',@all_host_ids).')';      my $host_id_re = '(?:'.join('|',@all_host_ids).')';
     my @alldelayed = grep(/\.$host_id_re$/, readdir(DIRHANDLE));      my @alldelayed = grep(/\.$host_id_re$/, readdir(DIRHANDLE));
     closedir(DIRHANDLE);      closedir(DIRHANDLE);
Line 1206  sub MakeLondConnection { Line 1199  sub MakeLondConnection {
   .GetServerPort());    .GetServerPort());
   
     my $Connection = LondConnection->new(&GetServerHost(),      my $Connection = LondConnection->new(&GetServerHost(),
  &GetServerPort());   &GetServerPort(),
    &GetHostId());
   
     if($Connection eq undef) { # Needs to be more robust later.      if($Connection eq undef) { # Needs to be more robust later.
  Log("CRITICAL","Failed to make a connection with lond.");   Log("CRITICAL","Failed to make a connection with lond.");
Line 1496  sub GetServerHost { Line 1490  sub GetServerHost {
   
 =pod  =pod
   
   =head2 GetServerId
   
   Returns the hostid whose lond we talk with.
   
   =cut
   
   sub GetHostId {
       return $RemoteHostId; # Setup by the fork.
   }
   
   =pod
   
 =head2 GetServerPort  =head2 GetServerPort
   
 Returns the lond port number.  Returns the lond port number.
Line 1749  sub ChildProcess { Line 1755  sub ChildProcess {
 #  Create a new child for host passed in:  #  Create a new child for host passed in:
   
 sub CreateChild {  sub CreateChild {
     my ($host, $socket) = @_;      my ($host, $hostid) = @_;
   
     my $sigset = POSIX::SigSet->new(SIGINT);      my $sigset = POSIX::SigSet->new(SIGINT);
     sigprocmask(SIG_BLOCK, $sigset);      sigprocmask(SIG_BLOCK, $sigset);
Line 1762  sub CreateChild { Line 1768  sub CreateChild {
  sigprocmask(SIG_UNBLOCK, $sigset);   sigprocmask(SIG_UNBLOCK, $sigset);
   
     } else { # child.      } else { # child.
    $RemoteHostId = $hostid;
  ShowStatus("Connected to ".$RemoteHost);   ShowStatus("Connected to ".$RemoteHost);
  $SIG{INT} = 'DEFAULT';   $SIG{INT} = 'DEFAULT';
  sigprocmask(SIG_UNBLOCK, $sigset);   sigprocmask(SIG_UNBLOCK, $sigset);
  if(defined $socket) {   &ChildProcess(); # Does not return.
     &ChildProcess($socket);  
  } else {  
     ChildProcess; # Does not return.  
  }  
     }      }
 }  }
   
Line 1797  sub parent_client_connection { Line 1800  sub parent_client_connection {
  my ($event)   = @_;   my ($event)   = @_;
  my $watcher   = $event->w;   my $watcher   = $event->w;
  my $socket    = $watcher->fd;   my $socket    = $watcher->fd;
  if ($hosts_tab) {   my $connection = $socket->accept(); # Accept the client connection.
    Event->io(cb      => \&get_remote_hostname,
     # Lookup the host associated with this socket:    poll    => 'r',
     data    => "",
     my $host = $listening_to{$socket};    fd      => $connection);
   
     # Start the child:  
   
   
   
     &Debug(9,"Creating child for $host (parent_client_connection)");  
     &CreateChild($host, $socket);  
       
     # Clean up the listen since now the child takes over until it exits.  
   
     $watcher->cancel(); # Nolonger listening to this event  
     delete($listening_to{$socket});  
     delete($parent_dispatchers{$host});  
     $socket->close();  
   
  } else {  
     my $connection = $socket->accept(); # Accept the client connection.  
     Event->io(cb      => \&get_remote_hostname,  
       poll    => 'r',  
       data    => "",  
       fd      => $connection);  
  }  
     }      }
 }  }
   
Line 1852  sub get_remote_hostname { Line 1833  sub get_remote_hostname {
  }   }
   
  &Debug(5,"Creating child for $data (parent_client_connection)");   &Debug(5,"Creating child for $data (parent_client_connection)");
  &CreateChild($data);   my ($hostname,$lonid) = split(':',$data,2);
    &CreateChild($hostname,$lonid);
   
  # Clean up the listen since now the child takes over until it exits.   # Clean up the listen since now the child takes over until it exits.
  $watcher->cancel(); # Nolonger listening to this event   $watcher->cancel(); # Nolonger listening to this event
Line 1973  sub server_died { Line 1955  sub server_died {
  if($host) { # It's for real...   if($host) { # It's for real...
     &Debug(9, "Caught sigchild for $host");      &Debug(9, "Caught sigchild for $host");
     delete($ChildHash{$pid});      delete($ChildHash{$pid});
     if ($hosts_tab) {      &parent_clean_up($host);
  &parent_listen($host);  
     } else {  
  &parent_clean_up($host);  
     }  
       
  } else {   } else {
     &Debug(5, "Caught sigchild for pid not in hosts hash: $pid");      &Debug(5, "Caught sigchild for pid not in hosts hash: $pid");
  }   }
Line 2036  Log("CRITICAL", "--------------- Startin Line 2014  Log("CRITICAL", "--------------- Startin
 LondConnection::ReadConfig;               # Read standard config files.  LondConnection::ReadConfig;               # Read standard config files.
   
 $RemoteHost = "[parent]";  $RemoteHost = "[parent]";
 if ($hosts_tab) {  &listen_on_common_socket();
     &listen_on_all_unix_sockets();  
 } else {  
     &listen_on_common_socket();  
 }  
   
 $RemoteHost = "Parent Server";  $RemoteHost = "Parent Server";
   
Line 2065  $parent_handlers{INT} = Event->signal(cb Line 2039  $parent_handlers{INT} = Event->signal(cb
 $parent_handlers{TERM} = Event->signal(cb       => \&Terminate,  $parent_handlers{TERM} = Event->signal(cb       => \&Terminate,
        desc     => "Parent TERM handler",         desc     => "Parent TERM handler",
        signal   => "TERM");         signal   => "TERM");
 if ($hosts_tab) {  $parent_handlers{HUP}  = Event->signal(cb       => \&KillThemAll,
     $parent_handlers{HUP}  = Event->signal(cb       => \&Restart,         desc     => "Parent HUP handler.",
    desc     => "Parent HUP handler.",         signal   => "HUP");
    signal   => "HUP");  
 } else {  
     $parent_handlers{HUP}  = Event->signal(cb       => \&KillThemAll,  
    desc     => "Parent HUP handler.",  
    signal   => "HUP");  
 }  
 $parent_handlers{USR1} = Event->signal(cb       => \&CheckKids,  $parent_handlers{USR1} = Event->signal(cb       => \&CheckKids,
        desc     => "Parent USR1 handler",         desc     => "Parent USR1 handler",
        signal   => "USR1");         signal   => "USR1");
Line 2154  sub UpdateKids { Line 2122  sub UpdateKids {
     # The down side is transactions that are in flight will get timed out      # The down side is transactions that are in flight will get timed out
     # (lost unless they are critical).      # (lost unless they are critical).
   
     if ($hosts_tab) {      &KillThemAll();
  &Restart();  
     } else {  
  &KillThemAll();  
     }  
 }  }
   
   
Line 2242  sub Terminate { Line 2206  sub Terminate {
     exit 0;      exit 0;
   
 }  }
   
   sub my_hostname {
       use Sys::Hostname;
       my $name = &hostname();
       &Debug(9,"Name is $name");
       return $name;
   }
   
 =pod  =pod
   
 =head1 Theory  =head1 Theory

Removed from v.1.80  
changed lines
  Added in v.1.81


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