--- projects/cms/source/host/ihost-perl/ihost.pl 2001/03/15 09:46:18 1.31 +++ projects/cms/source/host/ihost-perl/ihost.pl 2001/03/22 08:53:59 1.34 @@ -10,7 +10,7 @@ # - pjm2@ukc.ac.uk # # $Author: pjm2 $ -# $Id: ihost.pl,v 1.31 2001/03/15 09:46:18 pjm2 Exp $ +# $Id: ihost.pl,v 1.34 2001/03/22 08:53:59 pjm2 Exp $ #------------------------------------------------------------ $| = 1; @@ -45,7 +45,7 @@ $filter_manager_addr = $ARGV[0]; $filter_manager_port = $ARGV[1]; $seq_no = 1; -$retry_wait = 600; +$retry_wait = 60; # write our PID to a file $pidfile = "/var/tmp/ihost.pid"; @@ -120,8 +120,8 @@ sub tcp_configure() { print $sock "STARTCONFIG\n"; $response = <$sock>; - if (!chop $response eq "OK") { - print "The i-scream server rejected the STARTCONFIG command. Terminated."; + if ($response && !($response eq "OK\n")) { + print "The i-scream server rejected the STARTCONFIG command.\n"; close($sock); wait_then_retry(); next; @@ -131,6 +131,12 @@ sub tcp_configure() { print $sock "LASTMODIFIED\n"; $response = <$sock>; + if (!$response) { + print "The i-scream server did not return anything for the LASTMODIFIED command.\n"; + close($sock); + wait_then_retry(); + next; + } chop $response; $last_modified = $response; @@ -138,6 +144,12 @@ sub tcp_configure() { print $sock "FILELIST\n"; $response = <$sock>; + if (!$response) { + print "The i-scream server did not provide a configuration file list.\n"; + close($sock); + wait_then_retry(); + next; + } chop $response; $file_list = $response; @@ -145,6 +157,12 @@ sub tcp_configure() { print $sock "FQDN\n"; $response = <$sock>; + if (!$response) { + print "The i-scream server did not tell us our FQDN.\n"; + close($sock); + wait_then_retry(); + next; + } chop $response; $fqdn = $response; @@ -152,11 +170,23 @@ sub tcp_configure() { print $sock "UDPUpdateTime\n"; $response = <$sock>; + if (!$response) { + print "The i-scream server did not give us a UDPUpdateTime.\n"; + close($sock); + wait_then_retry(); + next; + } chop $response; $udp_update_time = $response; print $sock "TCPUpdateTime\n"; $response = <$sock>; + if (!$response) { + print "The i-scream server did not give us a TCPUpdateTime.\n"; + close($sock); + wait_then_retry(); + next; + } chop $response; $tcp_update_time = $response; @@ -164,8 +194,7 @@ sub tcp_configure() { print $sock "ENDCONFIG\n"; $response = <$sock>; - chomp $response; - if (!$response eq "OK") { + if ($response && !($response eq "OK\n")) { print "ENDCONFIG command to server failed. Terminated.\n"; close($sock); wait_then_retry(); @@ -176,14 +205,14 @@ sub tcp_configure() { print $sock "FILTER\n"; $response = <$sock>; - unless (defined($response)) { + if (!$response) { print "Failed: Could not get a filter address from the filter manager.\n"; close($sock); wait_then_retry(); next; } chop $response; - $response =~ /(.*);(.*);(.*)/; + $response =~ /^(.*);(.*);(.*)/; if ($response eq "ERROR") { print "There are no active configured filters for your host.\n"; close($sock); @@ -202,12 +231,11 @@ sub tcp_configure() { print $sock "END\n"; $response = <$sock>; - chop $response; - if ($response eq "OK") { + if ($response && ($response eq "OK\n")) { print "Host successfully configured via TCP.\n" } else { - print "The server failed the host configuration on the END command."; + print "The server failed the host configuration on the END command.\n"; close($sock); wait_then_retry(); next; @@ -255,7 +283,8 @@ sub send_udp_packet() { } $disk_info .= ""; - my($ip) = inet_ntoa(scalar(gethostbyname(hostname())) || 'localhost'); + my($ip); + $ip = inet_ntoa(scalar(gethostbyname(hostname())) || 'localhost') or $ip = 'localhost'; # Build the XML packet this way, as we can clearly # see the structure and contents... I like this ;-) @@ -332,9 +361,13 @@ EOF # send_tcp_heartbeat # Establishes a TCP connection to an i-scream filter. # The heartbeat is used as a guaranteed "I'm alive" delivery mechanism. +# If we need to reconfigure, then we complete the heartbeat before +# doing so. #----------------------------------------------------------------------- sub send_tcp_heartbeat() { + my ($doReconfigure) = 0; + my($sock) = new IO::Socket::INET( PeerAddr => $filter_addr, PeerPort => $tcp_port, @@ -351,9 +384,7 @@ sub send_tcp_heartbeat() { print $sock "HEARTBEAT\n"; $response = <$sock>; - return if (!defined $response); - chop $response; - if (!$response eq "OK") { + if (!$response eq "OK\n") { close($sock); print "Server gave wrong response to HEARTBEAT: $response\n"; &tcp_configure(); @@ -362,9 +393,7 @@ sub send_tcp_heartbeat() { print $sock "CONFIG\n"; $response = <$sock>; - return if (!defined $response); - chop $response; - if (!$response eq "OK") { + if (!$response eq "OK\n") { close($sock); print "Server gave wrong response to CONFIG: $response\n"; &tcp_configure(); @@ -373,9 +402,7 @@ sub send_tcp_heartbeat() { print $sock "$file_list\n"; $response = <$sock>; - return if (!defined $response); - chop $response; - if (!$response eq "OK") { + if (!$response eq "OK\n") { close($sock); print "Server gave wrong response to file list: $response\n"; &tcp_configure(); @@ -384,15 +411,12 @@ sub send_tcp_heartbeat() { print $sock "$last_modified\n"; $response = <$sock>; - return if (!defined $response); - chop $response; - if ($response eq "ERROR") { + if ($response eq "ERROR\n") { close($sock); print "Server configuration changed. Reconfiguring with filter manager.\n"; - &tcp_configure(); - return; + $doReconfigure = 1; } - if (!$response eq "OK") { + if (!$response eq "OK\n") { close($sock); print "Server gave wrong response to HEARTBEAT: $response\n"; &tcp_configure(); @@ -401,9 +425,7 @@ sub send_tcp_heartbeat() { print $sock "ENDHEARTBEAT\n"; $response = <$sock>; - return if (!defined $response); - chop $response; - if (!$response eq "OK") { + if (!$response eq "OK\n") { close($sock); print "Server gave wrong response to ENDHEARTBEAT: $response\n"; &tcp_configure(); @@ -412,6 +434,8 @@ sub send_tcp_heartbeat() { close($sock); print "^"; + + &tcp_configure() if $doReconfigure; return; }