--- loncom/loncnew 2003/09/02 10:34:47 1.22 +++ loncom/loncnew 2003/09/15 09:24:49 1.23 @@ -2,7 +2,7 @@ # The LearningOnline Network with CAPA # lonc maintains the connections to remote computers # -# $Id: loncnew,v 1.22 2003/09/02 10:34:47 foxr Exp $ +# $Id: loncnew,v 1.23 2003/09/15 09:24:49 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -45,6 +45,9 @@ # Change log: # $Log: loncnew,v $ +# Revision 1.23 2003/09/15 09:24:49 foxr +# Add use strict and fix all the fallout from that. +# # Revision 1.22 2003/09/02 10:34:47 foxr # - Fix errors in host dead detection logic (too many cases where the # retries left were not getting incremented or just not checked). @@ -114,7 +117,7 @@ # complete coding to support deferred transactions. # # - +use strict; use lib "/home/httpd/lib/perl/"; use lib "/home/foxr/newloncapa/types"; use Event qw(:DEFAULT ); @@ -278,7 +281,7 @@ sub GetPeername { my $peerip; if($AdrFamily == AF_INET) { ($peerport, $peerip) = sockaddr_in($peer); - my $peername = gethostbyaddr($iaddr, $AdrFamily); + my $peername = gethostbyaddr($peerip, $AdrFamily); return $peername; } elsif ($AdrFamily == AF_UNIX) { my $peerfile; @@ -299,7 +302,7 @@ sub Debug { my $level = shift; my $message = shift; if ($level <= $DebugLevel) { - Log("INFO", "-Debug- $message host = $RemotHost"); + Log("INFO", "-Debug- $message host = $RemoteHost"); } } @@ -368,7 +371,7 @@ sub Tick { ($WorkQueue->Count() == 0)) { # Idle connections and nothing to do? $IdleSeconds++; if($IdleSeconds > $IdleTimeout) { # Prune a connection... - $Socket = $IdleConnections->pop(); + my $Socket = $IdleConnections->pop(); KillSocket($Socket); } } else { @@ -377,7 +380,7 @@ sub Tick { # # For each inflight transaction, tick down its timeout counter. # - foreach $item (keys %ActiveTransactions) { + foreach my $item (keys %ActiveTransactions) { my $Socket = $ActiveTransactions{$item}->getServer(); $Socket->Tick(); } @@ -392,7 +395,7 @@ sub Tick { $Requests : $MaxConnectionCount; Debug(1,"Work but no connections, start ".$Connections." of them"); my $successCount = 0; - for ($i =0; $i < $Connections; $i++) { + for (my $i =0; $i < $Connections; $i++) { $successCount += MakeLondConnection(); } if($successCount == 0) { # All connections failed: @@ -452,7 +455,7 @@ sub ServerToIdle { # If there's work to do, start the transaction: - $reqdata = $WorkQueue->dequeue(); # This is a LondTransaction + my $reqdata = $WorkQueue->dequeue(); # This is a LondTransaction unless($reqdata eq undef) { Debug(9, "Queue gave request data: ".$reqdata->getRequest()); &StartRequest($Socket, $reqdata); @@ -586,7 +589,7 @@ sub CompleteTransaction { StartClientReply($Transaction, $data); } else { # Delete deferred transaction file. Log("SUCCESS", "A delayed transaction was completed"); - LogPerm("S:$Client:".$Transaction->getRequest()); + LogPerm("S:$Transaction->getClient() :".$Transaction->getRequest()); unlink $Transaction->getFile(); } } @@ -683,7 +686,7 @@ Close all connections open on lond prior =cut sub CloseAllLondConnections { - foreach $Socket (keys %ActiveConnections) { + foreach my $Socket (keys %ActiveConnections) { KillSocket($Socket); } } @@ -804,7 +807,7 @@ sub LondReadable { my $Socket = $Watcher->data; my $client = undef; - &Debug(6,"LondReadable called state = ".$State); + &Debug(6,"LondReadable called state = ".$Socket->GetState()); my $State = $Socket->GetState(); # All action depends on the state. @@ -1075,8 +1078,7 @@ sub QueueDelayed { Debug(4, "Delayed path: ".$path); opendir(DIRHANDLE, $path); - @alldelayed = grep /\.$RemoteHost$/, readdir DIRHANDLE; - Debug(4, "Got ".$alldelayed." delayed files"); + my @alldelayed = grep /\.$RemoteHost$/, readdir DIRHANDLE; closedir(DIRHANDLE); my $dfname; my $reqfile; @@ -1133,7 +1135,7 @@ sub MakeLondConnection { $Connection->SetTimeoutCallback(\&SocketTimeout); - $event = Event->io(fd => $Socket, + my $event = Event->io(fd => $Socket, poll => 'w', cb => \&LondWritable, data => $Connection, @@ -1189,7 +1191,7 @@ sub StartRequest { $ActiveTransactions{$Lond} = $Request; $Lond->InitiateTransaction($Request->getRequest()); - $event = Event->io(fd => $Socket, + my $event = Event->io(fd => $Socket, poll => "w", cb => \&LondWritable, data => $Lond, @@ -1512,7 +1514,7 @@ sub CreateChild { my $host = shift; $RemoteHost = $host; Log("CRITICAL", "Forking server for ".$host); - $pid = fork; + my $pid = fork; if($pid) { # Parent $RemoteHost = "Parent"; $ChildHash{$pid} = $RemoteHost; @@ -1520,7 +1522,7 @@ sub CreateChild { } else { # child. ShowStatus("Connected to ".$RemoteHost); - $SIG{INT} = DEFAULT; + $SIG{INT} = 'DEFAULT'; sigprocmask(SIG_UNBLOCK, $sigset); ChildProcess; # Does not return. } @@ -1557,7 +1559,7 @@ if ($childpid != 0) { # ShowStatus("Parent writing pid file:"); -$execdir = $perlvar{'lonDaemons'}; +my $execdir = $perlvar{'lonDaemons'}; open (PIDSAVE, ">$execdir/logs/lonc.pid"); print PIDSAVE "$$\n"; close(PIDSAVE); @@ -1576,7 +1578,7 @@ Log("CRITICAL", "--------------- Startin my $HostIterator = LondConnection::GetHostIterator; while (! $HostIterator->end()) { - $hostentryref = $HostIterator->get(); + my $hostentryref = $HostIterator->get(); CreateChild($hostentryref->[0]); $HostIterator->next(); } @@ -1596,9 +1598,9 @@ $SIG{HUP} = \&Restart; $SIG{USR1} = \&CheckKids; while(1) { - $deadchild = wait(); + my $deadchild = wait(); if(exists $ChildHash{$deadchild}) { # need to restart. - $deadhost = $ChildHash{$deadchild}; + my $deadhost = $ChildHash{$deadchild}; delete($ChildHash{$deadchild}); Log("WARNING","Lost child pid= ".$deadchild. "Connected to host ".$deadhost); @@ -1628,7 +1630,7 @@ sub CheckKids { my $now=time; my $local=localtime($now); print $fh "LONC status $local - parent $$ \n\n"; - foreach $pid (keys %ChildHash) { + foreach my $pid (keys %ChildHash) { Debug(2, "Sending USR1 -> $pid"); kill 'USR1' => $pid; # Tell Child to report status. sleep 1; # Wait so file doesn't intermix. @@ -1646,7 +1648,7 @@ the config file. =cut sub Restart { - KillThemAll; # First kill all the children. + &KillThemAll; # First kill all the children. Log("CRITICAL", "Restarting"); my $execdir = $perlvar{'lonDaemons'}; unlink("$execdir/logs/lonc.pid"); @@ -1665,7 +1667,7 @@ SIGHUP. Responds to sigint and sigterm. sub KillThemAll { Debug(2, "Kill them all!!"); local($SIG{CHLD}) = 'IGNORE'; # Our children >will< die. - foreach $pid (keys %ChildHash) { + foreach my $pid (keys %ChildHash) { my $serving = $ChildHash{$pid}; Debug(2, "Killing lonc for $serving pid = $pid"); ShowStatus("Killing lonc for $serving pid = $pid");