Changeset 116

Show
Ignore:
Timestamp:
08/20/07 20:41:56 (1 year ago)
Author:
eric
Message:

Revmoved key timeout thread and replaced it with a NSObject performSelector:withObject:afterDelay. No need to addKeysWithoutInteraction in a seperate thread.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/eric/AgentController.m

    r111 r116  
    143143                if((status & 1) && ([agent isRunning])) 
    144144                { 
    145                         [NSThread detachNewThreadSelector:@selector(addKeysToAgentWithoutInteractionInNewThread) 
    146                                                  toTarget:self withObject:self]; 
     145                        [keychain addKeysToAgentWithInteraction:NO]; 
    147146                } 
    148147        }        
     
    222221 
    223222                [allKeysOnAgentLock unlock]; 
    224  
    225                 [NSThread detachNewThreadSelector:@selector(addKeysToAgentWithoutInteractionInNewThread) 
    226                                                                 toTarget:self withObject:self]; 
     223                                 
     224                [keychain addKeysToAgentWithInteraction:NO]; 
    227225        } 
    228226} 
     
    281279                allKeysOnAgent = YES; 
    282280                [allKeysOnAgentLock unlock]; 
     281                 
     282                if ([[NSUserDefaults standardUserDefaults] integerForKey:KeyTimeoutString] > 0) 
     283                { 
     284                        // Self firing timer with reset 
     285                        [[self class] cancelPreviousPerformRequestsWithTarget: self ]; 
     286                        [self performSelector: @selector(removeKeysFromAgent:)  
     287                                           withObject: nil 
     288                                           afterDelay: [[NSUserDefaults standardUserDefaults] integerForKey:KeyTimeoutString] * 60.00 ]; 
     289                         
     290                } 
    283291                 
    284292                [[Controller sharedController] setStatus:YES]; 
     
    336344                        && (![keychain addingKeys]) && (status & 1) && ([agent isRunning])) 
    337345                { 
    338                         [NSThread detachNewThreadSelector:@selector(addKeysToAgentWithoutInteractionInNewThread) 
    339                                 toTarget:self withObject:self]; 
     346                        [keychain addKeysToAgentWithInteraction:NO]; 
    340347                } 
    341348 
     
    444451        if([agent isRunning]) 
    445452        { 
     453         
    446454                [NSThread detachNewThreadSelector:@selector(addKeysToAgentInNewThread) 
    447455                                                        toTarget:self withObject:nil]; 
     
    465473                               inMainThread:YES]; 
    466474        } 
    467  
    468         [pool release]; 
    469 } 
    470  
    471 - (void)addKeysToAgentWithoutInteractionInNewThread 
    472 { 
    473         NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
    474  
    475         [keychain addKeysToAgentWithInteraction:NO]; 
    476475 
    477476        [pool release]; 
  • branches/eric/Controller.m

    r110 r116  
    3939 
    4040        conn = [NSConnection defaultConnection]; 
    41          
     41 
    4242        [conn runInNewThread]; 
    4343        [conn removeRunLoop:[NSRunLoop currentRunLoop]]; 
  • branches/eric/Libs/SSHAgent.m

    r115 r116  
    639639                [self setKeysOnAgent:nil]; 
    640640 
    641         else if ([[notification name] isEqualToString:@"AgentFilled"]) 
     641        else if ([[notification name] isEqualToString:@"AgentFilled"])  
    642642                [self setKeysOnAgent:[[SSHAgent currentAgent] currentKeysOnAgent]]; 
    643643} 
  • branches/eric/Libs/SSHKeychain.h

    r91 r116  
    1010        BOOL addingKeys; 
    1111         
    12         int lastScheduled; 
    13  
    1412        /* Locks */ 
    1513        NSLock *keychainLock; 
    1614        NSLock *addingKeysLock; 
    17         NSLock *lastScheduledLock; 
    1815} 
    1916 
     
    4037- (BOOL)addKeysToAgent; 
    4138- (BOOL)addKeysToAgentWithInteraction:(BOOL)interaction; 
    42 - (void)removeKeysAfterTimeout:(id)object; 
    4339- (BOOL)removeKeysFromAgent; 
    4440 
  • branches/eric/Libs/SSHKeychain.m

    r92 r116  
    44#import "SSHKey.h" 
    55#import "SSHTool.h" 
     6#import "SSHAgent.h" 
    67 
    78#include <unistd.h> 
     
    3334        keychainLock = [[NSLock alloc] init]; 
    3435        addingKeysLock = [[NSLock alloc] init]; 
    35         lastScheduledLock = [[NSLock alloc] init]; 
    36         lastScheduled = -1; 
    3736         
    3837        [self resetToKeysWithPaths:paths]; 
     
    5150        [keychainLock release]; 
    5251        [addingKeysLock release]; 
    53         [lastScheduledLock release]; 
    5452        [agentSocketPath release]; 
    5553         
     
    109107} 
    110108 
    111 - (int) lastScheduled 
    112 { 
    113         [lastScheduledLock lock]; 
    114         int returnInt = lastScheduled; 
    115         [lastScheduledLock unlock]; 
    116  
    117         return returnInt; 
    118 } 
    119  
    120 - (void) setLastScheduled:(int) scheduledTime 
    121 { 
    122         [lastScheduledLock lock]; 
    123         lastScheduled = scheduledTime; 
    124         [lastScheduledLock unlock]; 
    125 } 
    126109 
    127110/* Returns the SSHKey at Index nr. */ 
     
    208191                return YES; 
    209192 
    210         if (!agentSocketPath || ![[NSFileManager defaultManager] isReadableFileAtPath:agentSocketPath]) 
     193        if (![[SSHAgent currentAgent] isRunning]) 
    211194                return NO; 
    212195         
     
    247230        } 
    248231         
    249         if ([[NSUserDefaults standardUserDefaults] integerForKey:KeyTimeoutString] > 0) 
    250         { 
    251                 int timeScheduled = time(nil); 
    252                 [self setLastScheduled:timeScheduled]; 
    253                  
    254                 [NSThread detachNewThreadSelector:@selector(removeKeysAfterTimeout:) toTarget:self  
    255                                                                 withObject:[NSNumber numberWithInt:timeScheduled]]; 
    256         } 
    257  
    258232        [[NSNotificationCenter defaultCenter]  postNotificationName:@"AgentFilled" object:nil]; 
    259233         
    260234        [self setAddingKeys:NO]; 
    261235        return YES; 
    262 } 
    263  
    264 /* Remove all keys from the ssh-agent from a NSTimer object. */ 
    265 - (void)removeKeysAfterTimeout:(id)object 
    266 { 
    267         NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
    268         int timeScheduled = [object intValue]; 
    269          
    270         sleep([[NSUserDefaults standardUserDefaults] integerForKey:KeyTimeoutString] * 60); 
    271          
    272         /* If the time this timeout was scheduled is still the most recent, go ahead and remove the keys */ 
    273         if (timeScheduled == [self lastScheduled])  
    274                 [self removeKeysFromAgent]; 
    275          
    276         [pool release]; 
    277236} 
    278237 
     
    282241        SSHTool *theTool = [SSHTool toolWithName:@"ssh-add"]; 
    283242 
    284         [self setLastScheduled:-1]; 
    285  
    286         if (!agentSocketPath || ![[NSFileManager defaultManager] isReadableFileAtPath:agentSocketPath]) 
     243        if (![[SSHAgent currentAgent] isRunning]) 
    287244                return NO; 
    288245