ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/ihost-perl/ihost.pl
(Generate patch)

Comparing projects/cms/source/host/ihost-perl/ihost.pl (file contents):
Revision 1.30 by pjm2, Thu Mar 15 09:44:08 2001 UTC vs.
Revision 1.35 by tdb, Wed Nov 14 14:17:12 2001 UTC

# Line 45 | Line 45 | $filter_manager_addr = $ARGV[0];
45   $filter_manager_port = $ARGV[1];
46  
47   $seq_no = 1;
48 < $retry_wait = 600;
48 > $retry_wait = 60;
49  
50   # write our PID to a file
51   $pidfile = "/var/tmp/ihost.pid";
# Line 75 | Line 75 | while (1) {
75      else {
76          $delay = $next_tcp;
77      }
78 <    `sleep $delay`;
78 >    sleep $delay;
79   }
80  
81   # we'll probably never get here...
# Line 90 | Line 90 | exit(0);
90   #-----------------------------------------------------------------------
91   sub wait_then_retry() {
92      print "Will retry configuration with filter manager in $retry_wait seconds.\n";
93 <    `sleep $retry_wait`;
93 >    sleep $retry_wait;
94   }
95  
96  
# Line 102 | Line 102 | sub wait_then_retry() {
102   #-----------------------------------------------------------------------
103   sub tcp_configure() {
104      
105 <    while (1 == 1) {
105 >    while (1) {
106          my($sock) = new IO::Socket::INET(
107                                           PeerAddr => $filter_manager_addr,
108                                           PeerPort => $filter_manager_port,
# Line 120 | Line 120 | sub tcp_configure() {
120      
121          print $sock "STARTCONFIG\n";
122          $response = <$sock>;
123 <        if (!chop $response eq "OK") {
124 <            print "The i-scream server rejected the STARTCONFIG command.  Terminated.";
123 >        if ($response && !($response eq "OK\n")) {
124 >            print "The i-scream server rejected the STARTCONFIG command.\n";
125              close($sock);
126              wait_then_retry();
127              next;
# Line 131 | Line 131 | sub tcp_configure() {
131      
132          print $sock "LASTMODIFIED\n";
133          $response = <$sock>;
134 +        if (!$response) {
135 +            print "The i-scream server did not return anything for the LASTMODIFIED command.\n";
136 +            close($sock);
137 +            wait_then_retry();
138 +            next;
139 +        }
140          chop $response;
141          $last_modified = $response;
142      
# Line 138 | Line 144 | sub tcp_configure() {
144  
145          print $sock "FILELIST\n";
146          $response = <$sock>;
147 +        if (!$response) {
148 +            print "The i-scream server did not provide a configuration file list.\n";
149 +            close($sock);
150 +            wait_then_retry();
151 +            next;
152 +        }
153          chop $response;
154          $file_list = $response;
155  
# Line 145 | Line 157 | sub tcp_configure() {
157  
158          print $sock "FQDN\n";
159          $response = <$sock>;
160 +        if (!$response) {
161 +            print "The i-scream server did not tell us our FQDN.\n";
162 +            close($sock);
163 +            wait_then_retry();
164 +            next;
165 +        }
166          chop $response;
167          $fqdn = $response;
168  
# Line 152 | Line 170 | sub tcp_configure() {
170  
171          print $sock "UDPUpdateTime\n";
172          $response = <$sock>;
173 +        if (!$response) {
174 +            print "The i-scream server did not give us a UDPUpdateTime.\n";
175 +            close($sock);
176 +            wait_then_retry();
177 +            next;
178 +        }
179          chop $response;
180          $udp_update_time = $response;
181  
182          print $sock "TCPUpdateTime\n";
183          $response = <$sock>;
184 +        if (!$response) {
185 +            print "The i-scream server did not give us a TCPUpdateTime.\n";
186 +            close($sock);
187 +            wait_then_retry();
188 +            next;
189 +        }
190          chop $response;
191          $tcp_update_time = $response;
192      
# Line 164 | Line 194 | sub tcp_configure() {
194  
195          print $sock "ENDCONFIG\n";
196          $response = <$sock>;
197 <        chomp $response;
168 <        if (!$response eq "OK") {
197 >        if ($response && !($response eq "OK\n")) {
198              print "ENDCONFIG command to server failed.  Terminated.\n";
199              close($sock);
200              wait_then_retry();
# Line 176 | Line 205 | sub tcp_configure() {
205      
206          print $sock "FILTER\n";
207          $response = <$sock>;
208 <        unless (defined($response)) {
208 >        if (!$response) {
209              print "Failed: Could not get a filter address from the filter manager.\n";
210              close($sock);
211              wait_then_retry();
212              next;
213          }
214          chop $response;
215 <        $response =~ /(.*);(.*);(.*)/;
215 >        $response =~ /^(.*);(.*);(.*)/;
216          if ($response eq "ERROR") {
217              print "There are no active configured filters for your host.\n";
218              close($sock);
# Line 202 | Line 231 | sub tcp_configure() {
231  
232          print $sock "END\n";
233          $response = <$sock>;
234 <        chop $response;
206 <        if ($response eq "OK") {
234 >        if ($response && ($response eq "OK\n")) {
235              print "Host successfully configured via TCP.\n"
236          }
237          else {
238 <            print "The server failed the host configuration on the END command.";
238 >            print "The server failed the host configuration on the END command.\n";
239              close($sock);
240              wait_then_retry();
241              next;
# Line 255 | Line 283 | sub send_udp_packet() {
283      }
284      $disk_info .= "</disk>";
285  
286 <    my($ip) = inet_ntoa(scalar(gethostbyname(hostname())) || 'localhost');
286 >    my($ip);
287 >    $ip = inet_ntoa(scalar(gethostbyname(hostname())) || 'localhost') or $ip = 'localhost';
288  
289      # Build the XML packet this way, as we can clearly
290      # see the structure and contents... I like this ;-)
# Line 332 | Line 361 | EOF
361   # send_tcp_heartbeat
362   # Establishes a TCP connection to an i-scream filter.
363   # The heartbeat is used as a guaranteed "I'm alive" delivery mechanism.
364 + # If we need to reconfigure, then we complete the heartbeat before
365 + # doing so.
366   #-----------------------------------------------------------------------
367   sub send_tcp_heartbeat() {
368  
369 +    my ($doReconfigure) = 0;
370 +
371      my($sock) = new IO::Socket::INET(
372                                       PeerAddr => $filter_addr,
373                                       PeerPort => $tcp_port,
# Line 351 | Line 384 | sub send_tcp_heartbeat() {
384  
385      print $sock "HEARTBEAT\n";
386      $response = <$sock>;
387 <    return if (!defined $response);
355 <    chop $response;
356 <    if (!$response eq "OK") {
387 >    if (!$response eq "OK\n") {
388          close($sock);
389          print "Server gave wrong response to HEARTBEAT: $response\n";
390          &tcp_configure();
# Line 362 | Line 393 | sub send_tcp_heartbeat() {
393      
394      print $sock "CONFIG\n";
395      $response = <$sock>;
396 <    return if (!defined $response);
366 <    chop $response;
367 <    if (!$response eq "OK") {
396 >    if (!$response eq "OK\n") {
397          close($sock);
398          print "Server gave wrong response to CONFIG: $response\n";
399          &tcp_configure();
# Line 373 | Line 402 | sub send_tcp_heartbeat() {
402  
403      print $sock "$file_list\n";
404      $response = <$sock>;
405 <    return if (!defined $response);
377 <    chop $response;
378 <    if (!$response eq "OK") {
405 >    if (!$response eq "OK\n") {
406          close($sock);
407          print "Server gave wrong response to file list: $response\n";
408          &tcp_configure();
# Line 384 | Line 411 | sub send_tcp_heartbeat() {
411      
412      print $sock "$last_modified\n";
413      $response = <$sock>;
414 <    return if (!defined $response);
388 <    chop $response;
389 <    if ($response eq "ERROR") {
414 >    if ($response eq "ERROR\n") {
415          close($sock);
416          print "Server configuration changed.  Reconfiguring with filter manager.\n";
417 <        &tcp_configure();
393 <        return;
417 >        $doReconfigure = 1;
418      }
419 <    if (!$response eq "OK") {
419 >    if (!$response eq "OK\n") {
420          close($sock);
421          print "Server gave wrong response to HEARTBEAT: $response\n";
422          &tcp_configure();
# Line 401 | Line 425 | sub send_tcp_heartbeat() {
425      
426      print $sock "ENDHEARTBEAT\n";
427      $response = <$sock>;
428 <    return if (!defined $response);
405 <    chop $response;
406 <    if (!$response eq "OK") {
428 >    if (!$response eq "OK\n") {
429          close($sock);
430          print "Server gave wrong response to ENDHEARTBEAT: $response\n";
431          &tcp_configure();
# Line 412 | Line 434 | sub send_tcp_heartbeat() {
434      
435      close($sock);
436      print "^";
437 +    
438 +    &tcp_configure() if $doReconfigure;
439      
440      return;
441   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines