Changeset 83

Show
Ignore:
Timestamp:
12/27/05 17:04:41 (3 years ago)
Author:
mrowe
Message:

Update name of thePid and related to reflect that PID is an acronym. Add consistent getters + setters for member variables.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/AgentController.m

    r80 r83  
    609609        if([agent isRunning]) 
    610610        { 
    611                 [agentPID setIntValue:[agent pid]]; 
     611                [agentPID setIntValue:[agent PID]]; 
    612612                [agentGlobalAuthSocket setStringValue:[agent socketPath]]; 
    613613                [agentLocalAuthSocket setStringValue:[agent agentSocketPath]]; 
  • trunk/Libs/SSHAgent.h

    r82 r83  
    33@interface SSHAgent : NSObject  
    44{ 
    5         int thePid
     5        int thePID
    66        int s; 
    77 
     
    1515        NSLock *agentSocketPathLock; 
    1616        NSLock *keysOnAgentLock; 
    17         NSLock *thePidLock; 
     17        NSLock *thePIDLock; 
    1818} 
    1919 
    2020+ (id)currentAgent; 
    2121 
    22 - (BOOL)setSocketPath:(NSString *)path; 
     22- (void)setSocketPath:(NSString *)path; 
    2323 
    2424- (NSString *)socketPath; 
     
    2929 
    3030- (BOOL)isRunning; 
    31 - (int)pid
     31- (int)PID
    3232- (NSArray *)keysOnAgent; 
    3333 
  • trunk/Libs/SSHAgent.m

    r82 r83  
    5555        agentSocketPathLock = [[NSLock alloc] init]; 
    5656        keysOnAgentLock = [[NSLock alloc] init]; 
    57         thePidLock = [[NSLock alloc] init]; 
     57        thePIDLock = [[NSLock alloc] init]; 
    5858         
    5959        return self; 
     
    6767        [agentSocketPathLock dealloc]; 
    6868        [keysOnAgentLock dealloc]; 
    69         [thePidLock dealloc]; 
     69        [thePIDLock dealloc]; 
    7070 
    7171        [super dealloc]; 
     
    7373 
    7474/* Set the socket location for us to bind to. */ 
    75 - (BOOL)setSocketPath:(NSString *)path 
    76 { 
    77         if([self isRunning] == YES
     75- (void)setSocketPath:(NSString *)path 
     76{ 
     77        if ([self isRunning]
    7878        { 
    7979                NSLog(@"setSocketPath: can't change path while the agent is running."); 
    80                 return NO
     80                return
    8181        } 
    8282 
    8383        [socketPathLock lock]; 
    84  
    85         /* We don't use the socketPath method here, since we've just locked socketPathLock. */ 
    86         if(socketPath != nil) 
    87         { 
    88                 [socketPath release]; 
    89                 socketPath = nil; 
    90         } 
    91  
    92         socketPath = [[NSString stringWithString:path] retain]; 
     84        NSString *oldPath = socketPath; 
     85        socketPath = [path copy]; 
     86        [oldPath release]; 
    9387        [socketPathLock unlock]; 
    94          
    95         return YES; 
    9688} 
    9789 
     
    9991- (NSString *)socketPath 
    10092{ 
    101         NSString *returnString = nil; 
    102          
    10393        [socketPathLock lock]; 
    104          
    105         if(socketPath) 
    106         { 
    107                 returnString = [NSString stringWithString:socketPath]; 
    108         } 
    109          
     94        NSString *returnString = [[socketPath copy] autorelease]; 
    11095        [socketPathLock unlock]; 
    11196 
    11297        return returnString; 
     98} 
     99 
     100/* Set the socket location ssh-agent listens to. */ 
     101- (void)setAgentSocketPath:(NSString *)path 
     102{ 
     103        [agentSocketPathLock lock]; 
     104        NSString *oldPath = agentSocketPath; 
     105        agentSocketPath = [path copy]; 
     106        [oldPath release]; 
     107        [agentSocketPathLock unlock]; 
    113108} 
    114109 
     
    116111- (NSString *)agentSocketPath 
    117112{ 
    118         NSString *returnString = nil; 
    119  
    120113        [agentSocketPathLock lock]; 
    121          
    122         if(agentSocketPath) 
    123         { 
    124                 returnString = [NSString stringWithString:agentSocketPath]; 
    125         } 
    126          
     114        NSString *returnString = [[agentSocketPath copy] autorelease]; 
    127115        [agentSocketPathLock unlock]; 
    128116 
    129117        return returnString; 
     118} 
     119 
     120 
     121/* Return YES if the agent is (in theory) running, and NO if not. */ 
     122- (BOOL)isRunning 
     123{ 
     124        return [self PID] > 0; 
     125} 
     126 
     127/* Get the pid. */ 
     128- (int)PID 
     129{ 
     130        [thePIDLock lock]; 
     131        int returnInt = thePID; 
     132        [thePIDLock unlock]; 
     133 
     134        return returnInt; 
     135} 
     136 
     137- (void) setPID:(int)pid 
     138{ 
     139        [thePIDLock lock]; 
     140        thePID = pid; 
     141        [thePIDLock unlock]; 
     142} 
     143 
     144/* Return the keys on agent since last notification. */ 
     145- (NSArray *)keysOnAgent 
     146{ 
     147        [keysOnAgentLock lock]; 
     148        NSArray *returnArray = [[keysOnAgent copy] autorelease]; 
     149        [keysOnAgentLock unlock]; 
     150 
     151        return returnArray; 
     152} 
     153 
     154- (void) setKeysOnAgent:(NSArray *)keys 
     155{ 
     156        [keysOnAgentLock lock]; 
     157        NSArray *oldKeys = keysOnAgent; 
     158        keysOnAgent = [keys copy]; 
     159        [oldKeys release]; 
     160        [keysOnAgentLock unlock]; 
    130161} 
    131162 
     
    139170 
    140171        /* If the PID is > 0, the agent should (in theory) be running. */ 
    141         if([self pid] > 0) 
     172        if([self PID] > 0) 
    142173        { 
    143174                NSLog(@"Agent is already started"); 
     
    195226                if ([@"SSH_AGENT_PID" isEqualToString:[columns objectAtIndex:1]]) 
    196227                { 
    197                         [thePidLock lock]; 
    198                         thePid = [[columns objectAtIndex:2] intValue]; 
    199                         [thePidLock unlock]; 
     228                        [thePIDLock lock]; 
     229                        thePID = [[columns objectAtIndex:2] intValue]; 
     230                        [thePIDLock unlock]; 
    200231                } 
    201232        } 
    202233 
    203234        /* If the PID is > 0 but the socket path isn't filled, stop the agent and return -1. */ 
    204         if(([self pid] > 0) && (([self agentSocketPath] == nil) || ([agentSocketPath length] < 1))) 
     235        if(([self PID] > 0) && (([self agentSocketPath] == nil) || ([agentSocketPath length] < 1))) 
    205236        { 
    206237                NSLog(@"SSHAgent start: ssh-agent didn't give the output we expected"); 
     
    210241 
    211242        /* If there's no PID just return -1. */ 
    212         if([self pid] < 1) 
     243        if([self PID] < 1) 
    213244        { 
    214245                NSLog(@"SSHAgent start: ssh-agent didn't give the output we expected"); 
     
    231262{ 
    232263        /* We can't stop something if we haven't got the pid. */ 
    233         if([self pid] > 0) 
     264        if([self PID] > 0) 
    234265        { 
    235266                /* We don't need to check if this fails. We clean up the variables either way. */ 
    236                 kill([self pid], SIGTERM); 
     267                kill([self PID], SIGTERM); 
    237268 
    238269                [agentSocketPathLock lock]; 
     
    243274                [self closeSockets]; 
    244275 
    245                 [thePidLock lock]; 
    246                 thePid = 0; 
    247                 [thePidLock unlock]; 
     276                [thePIDLock lock]; 
     277                thePID = 0; 
     278                [thePIDLock unlock]; 
    248279 
    249280                [keysOnAgentLock lock]; 
     
    256287 
    257288        return YES; 
    258 } 
    259  
    260 /* Return YES if the agent is (in theory) running, and NO if not. */ 
    261 - (BOOL)isRunning 
    262 { 
    263         if([self pid] > 0) { return YES; } 
    264         else { return NO; } 
    265 } 
    266  
    267 /* Get the pid. */ 
    268 - (int)pid 
    269 { 
    270         int returnInt; 
    271  
    272         [thePidLock lock]; 
    273         returnInt = thePid; 
    274         [thePidLock unlock]; 
    275  
    276         return returnInt; 
    277 } 
    278  
    279 /* Return the keys on agent since last notification. */ 
    280 - (NSArray *)keysOnAgent 
    281 { 
    282         NSArray *returnArray = nil; 
    283  
    284         [keysOnAgentLock lock]; 
    285          
    286         if(keysOnAgent) 
    287         { 
    288                 returnArray = [NSArray arrayWithArray:keysOnAgent]; 
    289         } 
    290          
    291         [keysOnAgentLock unlock]; 
    292  
    293         return returnArray; 
    294289} 
    295290 
     
    640635        { 
    641636                keychain = [SSHKeychain currentKeychain]; 
    642  
    643637                if ([keychain count] > 0) 
    644638                        [keychain addKeysToAgent]; 
     
    655649{ 
    656650        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
    657         int currentPID = [self pid]; 
     651        int currentPID = [self PID]; 
    658652        while (getpgid(currentPID) != -1) 
    659653        { 
     
    665659                   we were monitoring will no longer exist.  Exit early to avoid notifying the user that the old 
    666660                   agent is gone */ 
    667                 if (currentPID != [self pid]) 
     661                if (currentPID != [self PID]) 
    668662                { 
    669663                        [pool release]; 
     
    715709 
    716710        /* If the PID is < 1, we assume the agent isn't running. */ 
    717         if([self pid] < 1) 
     711        if([self PID] < 1) 
    718712        { 
    719713                return nil;