[LON-CAPA-cvs] cvs: loncom / LondConnection.pm loncnew
foxr
lon-capa-cvs@mail.lon-capa.org
Wed, 02 Jul 2003 01:12:35 -0000
foxr Tue Jul 1 21:12:35 2003 EDT
Modified files:
/loncom LondConnection.pm loncnew
Log:
- Add some debugging to killthemall
- Add better error handling to LondReadable
- Remove tick logging in the timer handler.
Index: loncom/LondConnection.pm
diff -u loncom/LondConnection.pm:1.6 loncom/LondConnection.pm:1.7
--- loncom/LondConnection.pm:1.6 Thu Jun 12 22:56:45 2003
+++ loncom/LondConnection.pm Tue Jul 1 21:12:35 2003
@@ -1,7 +1,7 @@
# This module defines and implements a class that represents
# a connection to a lond daemon.
#
-# $Id: LondConnection.pm,v 1.6 2003/06/13 02:56:45 foxr Exp $
+# $Id: LondConnection.pm,v 1.7 2003/07/02 01:12:35 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -215,7 +215,7 @@
my $rv = $socket->recv($data, POSIX::BUFSIZ, 0);
my $errno = $! + 0; # Force numeric context.
- unless (defined($rv) && length($data)) { # Read failed,
+ unless (defined($rv) && (length($data)> 0)) {# Read failed,
if(($errno == POSIX::EWOULDBLOCK) ||
($errno == POSIX::EAGAIN) ||
($errno == POSIX::EINTR) ||
Index: loncom/loncnew
diff -u loncom/loncnew:1.11 loncom/loncnew:1.12
--- loncom/loncnew:1.11 Tue Jun 24 21:54:44 2003
+++ loncom/loncnew Tue Jul 1 21:12:35 2003
@@ -2,7 +2,7 @@
# The LearningOnline Network with CAPA
# lonc maintains the connections to remote computers
#
-# $Id: loncnew,v 1.11 2003/06/25 01:54:44 foxr Exp $
+# $Id: loncnew,v 1.12 2003/07/02 01:12:35 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -46,6 +46,11 @@
# Change log:
# $Log: loncnew,v $
+# Revision 1.12 2003/07/02 01:12:35 foxr
+# - Add some debugging to killthemall
+# - Add better error handling to LondReadable
+# - Remove tick logging in the timer handler.
+#
# Revision 1.11 2003/06/25 01:54:44 foxr
# Fix more problems with transaction failure.
#
@@ -71,6 +76,7 @@
use lib "/home/foxr/newloncapa/types";
use Event qw(:DEFAULT );
use POSIX qw(:signal_h);
+use POSIX;
use IO::Socket;
use IO::Socket::INET;
use IO::Socket::UNIX;
@@ -287,11 +293,7 @@
sub Tick {
my $client;
ShowStatus(GetServerHost()." Connection count: ".$ConnectionCount);
- Debug(10,"Tick");
- Debug(10," Current connection count: ".$ConnectionCount);
- foreach $client (keys %ActiveClients) {
- Debug(10," Have client: with id: ".$ActiveClients{$client});
- }
+
# Is it time to prune connection count:
@@ -523,6 +525,7 @@
my $Transaction = shift;
my $data = shift;
+
my $Client = $Transaction->getClient();
&Debug(8," Reply was: ".$data);
@@ -716,8 +719,10 @@
my $State = $Socket->GetState(); # All action depends on the state.
SocketDump(6, $Socket);
+ my $status = $Socket->Readable();
+ &Debug(2, "Socket->Readable returned: $status");
- if($Socket->Readable() != 0) {
+ if($status != 0) {
# bad return from socket read. Currently this means that
# The socket has become disconnected. We fail the transaction.
@@ -982,7 +987,7 @@
my $Handle = IO::File->new($reqfile);
my $cmd = <$Handle>;
chomp $cmd; # There may or may not be a newline...
- $cmd = $cmd."\ny"; # now for sure there's exactly one newline.
+ $cmd = $cmd."\n"; # now for sure there's exactly one newline.
my $Transaction = LondTransaction->new($cmd);
$Transaction->SetDeferred($reqfile);
QueueTransaction($Transaction);
@@ -1293,9 +1298,9 @@
=cut
-=pod
sub SignalledToDeath {
+ Debug(2,"Signalled to death!");
my ($signal) = @_;
chomp($signal);
Log("CRITICAL", "Abnormal exit. Child $$ for $RemoteHost "
@@ -1303,6 +1308,7 @@
LogPerm("F:lonc: $$ on $RemoteHost signalled to death: "
."\"$signal\"");
die("Signal abnormal end");
+ exit 0;
}
=head2 ChildProcess
@@ -1319,7 +1325,7 @@
$SIG{QUIT} = \&SignalledToDeath;
$SIG{HUP} = IGNORE;
$SIG{USR1} = IGNORE;
- $SIG{INT} = IGNORE;
+ $SIG{INT} = DEFAULT;
$SIG{CHLD} = IGNORE;
$SIG{__DIE__} = \&SignalledToDeath;
@@ -1346,15 +1352,21 @@
# Create a new child for host passed in:
sub CreateChild {
+ my $sigset = POSIX::SigSet->new(SIGINT);
+ sigprocmask(SIG_BLOCK, $sigset);
my $host = shift;
$RemoteHost = $host;
Log("CRITICAL", "Forking server for ".$host);
$pid = fork;
if($pid) { # Parent
$ChildHash{$pid} = $RemoteHost;
+ sigprocmask(SIG_UNBLOCK, $sigset);
+
} else { # child.
ShowStatus("Connected to ".$RemoteHost);
- ChildProcess;
+ $SIG{INT} = DEFAULT;
+ sigprocmask(SIG_UNBLOCK, $sigset);
+ ChildProcess; # Does not return.
}
}
@@ -1410,6 +1422,7 @@
CreateChild($hostentryref->[0]);
$HostIterator->next();
}
+$RemoteHost = "Parent Server";
# Maintain the population:
@@ -1418,8 +1431,10 @@
#
# Set up parent signals:
#
-$SIG{INT} = &KillThemAll;
-$SIG{TERM} = &KillThemAll;
+
+$SIG{INT} = \&KillThemAll;
+$SIG{TERM} = \&KillThemAll;
+
while(1) {
$deadchild = wait();
@@ -1432,8 +1447,31 @@
CreateChild($deadhost);
}
}
+
+=pod
+
+=head1 KillThemAll
+
+Signal handler that kills all children by sending them a
+SIGINT. Responds to sigint and sigterm.
+
+=cut
+
sub KillThemAll {
+ Debug(2, "Kill them all!!");
+ local($SIG{CHLD}) = 'IGNORE'; # Our children >will< die.
+ foreach $pid (keys %ChildHash) {
+ my $serving = $ChildHash{$pid};
+ Debug(2, "Killing lonc for $serving pid = $pid");
+ ShowStatus("Killing lonc for $serving pid = $pid");
+ Log("CRITICAL", "Killing lonc for $serving pid = $pid");
+ kill('INT', $pid);
+ }
+ Log("CRITICAL", "Killing the master process.");
+ exit
}
+
+=pod
=head1 Theory