| 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. |
|---|
| | 27 | my $key; |
|---|
| | 28 | ReadMode 4; # Turn off controls keys |
|---|
| | 29 | while (not defined ($key = ReadKey(-1))) { |
|---|
| | 30 | # No key yet |
|---|
| 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 | | } |
|---|
| | 32 | ReadMode 0; # Reset tty mode before exiting |
|---|