Show
Ignore:
Timestamp:
04/09/08 15:47:11 (8 months ago)
Author:
kindlund
Message:

Merging simpler_agent branch into trunk.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • honeyclient/trunk/bin/StartAgent.pl

    r1008 r1499  
    1 #!perl -w -Ilib 
     1#!perl -Ilib 
    22 
    33# $Id$ 
     
    77use Carp (); 
    88 
     9use Term::ReadKey; 
    910use HoneyClient::Util::Config qw(getVar); 
    1011use HoneyClient::Agent; 
     
    2122our $URL = HoneyClient::Agent->init(); 
    2223 
    23 our $agentState = undef; 
    24 my $tempState = undef; 
    25 our $faultDetected = 0; 
    26  
    2724print "URL: " . $URL. "\n"; 
    2825 
    29 sub _watchdogFaultHandler { 
    30  
    31     # Extract arguments. 
    32     my ($class, $res) = @_; 
    33  
    34     # Construct error message. 
    35     # Figure out if the error occurred in transport or over 
    36     # on the other side. 
    37     my $errMsg = $class->transport->status; # Assume transport error. 
    38  
    39     if (ref $res) { 
    40         $errMsg = $res->faultcode . ": ".  $res->faultstring . "\n"; 
    41     } 
    42  
    43     if (!$faultDetected) { 
    44         $LOG->error("Watchdog fault detected, recovering Agent daemon."); 
    45         $faultDetected = 1; 
    46     } 
    47     # XXX: Reenable this, eventually. 
    48     $LOG->error(__PACKAGE__ . "->_watchdogFaultHandler(): Error occurred during processing.\n" . $errMsg); 
    49     Carp::carp __PACKAGE__ . "->_watchdogFaultHandler(): Error occurred during processing.\n" . $errMsg; 
    50  
    51  
    52     # Regardless of the error, destroy the Agent process and reinitialize it. 
    53     # XXX: Sanity check this, eventually. 
    54     HoneyClient::Agent->destroy(); 
    55  
    56     # Wait for a small amount of time, in order for the killed process to release 
    57     # its control of the bound TCP port. 
    58     sleep 5; 
    59  
    60     $URL = HoneyClient::Agent->init(); 
    61  
    62     # Recreate a new stub handle, in case the global configuration has 
    63     # changed. 
    64     $stub = getClientHandle(address   => 'localhost', 
    65                             namespace => 'HoneyClient::Agent', 
    66                             fault_handler => \&_watchdogFaultHandler); 
    67  
    68     # Restore state information. 
    69     if (defined($agentState)) { 
    70         $som = $stub->updateState(encode_base64(nfreeze($agentState))); 
    71     } 
     26# Halt when we get any sort of keyboard input. 
     27my $key; 
     28ReadMode 4; # Turn off controls keys 
     29while (not defined ($key = ReadKey(-1))) { 
     30    # No key yet 
    7231} 
    73  
    74 $stub = getClientHandle(address   => 'localhost', 
    75                         namespace => 'HoneyClient::Agent', 
    76                         fault_handler => \&_watchdogFaultHandler); 
    77                  
    78 for (;;) { 
    79     # TODO: Make this a programmatic value. 
    80     sleep (5); 
    81     $som = $stub->getState(); 
    82     if (defined($som) and (ref($som) eq "SOAP::SOM")) { 
    83         $tempState = $som->result(); 
    84         if (defined($tempState)) { 
    85             # Make sure the new state is parsable, before saving it. 
    86             eval { 
    87                 $tempState = thaw(decode_base64($tempState)); 
    88             }; 
    89             if (!$@) { 
    90                 $agentState = $tempState; 
    91             } 
    92         } 
    93     } 
    94 
     32ReadMode 0; # Reset tty mode before exiting 
    9533 
    9634HoneyClient::Agent->destroy();