Changeset 381

Show
Ignore:
Timestamp:
05/25/07 19:14:14 (1 year ago)
Author:
kindlund
Message:

Housekeeping and testing of non-require use of Integrity object.
At first glance, it looks like the source of the thread crashing was the use of Storable objects between threads.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • honeyclient/branches/exp/kindlund-filesystem/lib/HoneyClient/Agent.pm

    r378 r381  
    196196# TODO: Include corresponding unit tests. 
    197197# XXX: Check if this is still needed. 
    198 #use HoneyClient::Agent::Integrity; 
     198use HoneyClient::Agent::Integrity; 
    199199 
    200200# Include Thread Libraries 
     
    377377# XXX: Disabled temporarily. 
    378378    if ($PERFORM_INTEGRITY_CHECKS) { 
    379         require HoneyClient::Agent::Integrity; 
     379#        require HoneyClient::Agent::Integrity; 
    380380        $gintegrity = HoneyClient::Agent::Integrity->new(); 
    381381        $gintegrity->closeFiles(); 
     
    708708            print "Creating a new run() child thread...\n"; 
    709709        } 
    710  
    711 # XXX: If the old thread is dead, we could potentially 
    712 # join it, in order to avoid detach warnings upon exit. 
    713710 
    714711        # Quickly define a temporary thread ID. 
     
    729726        _unlock($data); 
    730727 
    731         $thread = threads->create(\&childThread
     728        $thread = threads->create(\&worker
    732729                                  { 
    733730                                    'driver_name' => $driverName, 
     
    744741            # XXX: Debugging, remove eventually.  
    745742            print "Thread ID = " . $thread->tid() . "\n"; 
    746             #$data->{$driverName}->{'thread_id'} = $thread->tid(); 
    747743        } else { 
    748744            # XXX: Debugging, remove eventually.  
    749745            print "Thread ID = " . $thread->tid() . " (NOT RUNNING)\n"; 
    750             #print "Thread ID = undef\n"; 
    751             #$data->{$driverName}->{'thread_id'} = undef; 
    752746        } 
    753747 
    754748        # Release data lock. 
    755749        _unlock($data); 
    756  
    757 # XXX: Check to see if this works okay. 
    758 #        $thread->join(); 
    759750    } 
    760751 
     
    783774# to properly deal with exceptions/faults that occur within this 
    784775# thread. 
    785 sub childThread
     776sub worker
    786777 
    787778    # Extract arguments. 
     
    789780 
    790781    my $driverName = $args->{'driver_name'}; 
    791     my $integrity = $args->{'integrity'}; 
     782    my $integrity = $args->{'integrity'}; 
    792783 
    793784    # Temporary variable, used to hold thawed driver data. 
     
    795786 
    796787# XXX: Check if we need this. 
    797 #    threads->yield(); 
     788    threads->yield(); 
    798789 
    799790    # Trap all faults that may occur from these asynchronous operations. 
     
    813804        $data = _lock(); 
    814805 
    815         #if ($PERFORM_INTEGRITY_CHECKS) { 
    816         #    require HoneyClient::Agent::Integrity; 
    817         #    # XXX: WARNING - The $integrityState object data is NOT thread-safe 
    818         #    # (since it relies on external data stored on the file system). 
    819         #    # As such, do NOT try to call integrity checks on multiple, simultaneous 
    820         #    # asynchronous threaded drivers. 
    821         #    #$integrity = thaw($integrityState); 
    822         #    # Perform initial integrity baseline check. 
    823         #    #print "Initializing Integrity Check...\n"; 
    824         #    # TODO: Initialize Integrity Checks 
    825         #    $integrity = HoneyClient::Agent::Integrity->new(); 
    826         #} 
    827  
    828806        # Now, initialize each driver object.  
    829807        # Figure out which $driver object to use... 
    830808        my $driverClass = 'HoneyClient::Agent::Driver::Browser::' . $driverName; 
    831 # XXX: See if this is still needed. 
    832 #        eval "require $driverClass"; 
    833 #        if ($@) { 
    834 #            Carp::croak "$@"; 
    835 #        } 
    836809 
    837810        if (!defined($data->{$driverName}->{'state'})) { 
     
    864837        $data->{$driverName}->{'status'}->{'is_running'} = 1; 
    865838        $data->{$driverName}->{'state'} = $driver; 
    866  
    867 # XXX: Check to see if this is okay. 
    868 #       if ($driver->isFinished()) { 
    869 #           # Thread is about to finish, set the ID back to undef. 
    870 #           # This looks ugly, but setting it this early avoids the 
    871 #           # potential race condition of when the run() thread is finished 
    872 #           # and when updateState() checks for $driverData->{$driverName}->{'thread_id'} 
    873 #           # to be set to undef. 
    874 #           $data->{$driverName}->{'thread_id'} = undef; 
    875 #       } 
    876839 
    877840        # Release lock on stored driver state. 
     
    960923        $data->{$driverName}->{'state'} = $driver; 
    961924  
    962         # Thread is about to finish, set the ID back to undef. 
    963 # XXX: Check to see if this is okay. 
    964 #       $data->{$driverName}->{'thread_id'} = undef; 
    965  
    966925        # Release lock on stored driver state. 
    967926        _unlock($data); 
     
    969928        # XXX: Debugging, remove eventually.  
    970929        print "Exiting run() thread.\n"; 
    971         #print Dumper($driver); 
    972         # Verbose debugging: 
    973         #print Dumper($driver->status()); 
    974         # Short-hand debugging: 
    975         #my $status = $driver->status(); 
    976         #print "R(" . $status->{relative_links_remaining} . ") | [ " . 
    977         #      "V(" . $status->{links_remaining} . ") + ". 
    978         #      "P(" . $status->{links_processed} . ") = " . 
    979         #      "T(" . $status->{links_total} . ") ] " . 
    980         #      "| (" . $status->{percent_complete} . ")\n"; 
    981930    }; 
    982931     
     
    992941        _unlock(); 
    993942 
    994         # Acquire lock on stored driver state. 
    995         $data = _lock(); 
    996                   
    997         # Make sure we update our state to reflect ourself dying. 
    998 # XXX: Check to see if this is okay. 
    999 #       $data->{$driverName}->{'thread_id'} = undef; 
    1000  
    1001         # Release lock on stored driver state. 
    1002         _unlock($data); 
    1003      
    1004943        # TODO: Do proper fault queuing. 
    1005944        print "FAULT: " . $@ . "\n";