Changeset 388

Show
Ignore:
Timestamp:
05/29/07 13:27:36 (1 year ago)
Author:
kindlund
Message:

Improved temporary file cleanup code.

Files:

Legend:

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

    r386 r388  
    403403 
    404404# Base destructor function. 
    405 # Since none of our state data ever contains circular references, 
    406 # we can simply leave the garbage collection up to Perl's internal 
    407 # mechanism. 
    408 # XXX: Change this to destroy() and update the integrity module's 
    409 # with integrity->destroy() accordingly. 
    410 sub XDESTROY { 
     405sub destroy { 
     406    # Extract arguments. 
    411407    my $self = shift; 
    412408 
    413     # Delete any temporary files created. 
    414     my $parser = undef; 
    415     my $fname = undef; 
    416     foreach my $hive (@{$self->{hives_to_check}}) { 
    417         $parser = $self->{_baseline_parsers}->{$hive}; 
    418         if (defined($parser)) { 
    419             $fname = $parser->getFilename(); 
    420             if (defined($fname) && (-f $fname)) { 
    421                 # XXX: Change this to debug, eventually. 
    422                 $LOG->info("Deleting baseline of hive '" . $hive . "' in '" . 
    423                             $fname . "'."); 
    424                 if (!unlink($fname)) { 
    425                     $LOG->fatal("Error: Unable to unlink '" . $hive . "' hive data in '" . $fname ."'."); 
    426                     Carp::croak("Error: Unable to unlink '" . $hive . "' hive data in '" . $fname ."'."); 
    427                 } 
    428             } 
    429             delete($self->{_baseline_parsers}->{$hive}); 
    430         } 
    431         $parser = $self->{_checkpoint_parsers}->{$hive}; 
    432         if (defined($parser)) { 
    433             $fname = $parser->getFilename(); 
    434             if (defined($fname) && (-f $fname)) { 
    435                 # XXX: Change this to debug, eventually. 
    436                 $LOG->info("Deleting checkpoint of hive '" . $hive . "' in '" . 
    437                             $fname . "'."); 
    438                 if (!unlink($fname)) { 
    439                     $LOG->fatal("Error: Unable to unlink '" . $hive . "' hive data in '" . $fname ."'."); 
    440                     Carp::croak("Error: Unable to unlink '" . $hive . "' hive data in '" . $fname ."'."); 
    441                 } 
    442             } 
    443             delete($self->{_checkpoint_parsers}->{$hive}); 
    444         } 
    445     } 
     409    # Delete any temporary files created by the baseline 
     410    # parsers. 
     411    $self->_cleanupParsers($self->{_baseline_parsers}); 
    446412} 
    447413 
     
    16431609directory keys. 
    16441610 
     1611The $object->new() and $object->check() calls may generate a large 
     1612number of temporary files on disk.  If any of this code fails prematurely, 
     1613then it's likely these temporary files will still exist upon abnormal 
     1614termination.  As such, manual cleanup of these files in /tmp may be 
     1615required. 
     1616 
    16451617For more information about the limitations of this module, please see: 
    16461618