Changeset 83
- Timestamp:
- 12/27/05 17:04:41 (3 years ago)
- Files:
-
- trunk/AgentController.m (modified) (1 diff)
- trunk/Libs/SSHAgent.h (modified) (3 diffs)
- trunk/Libs/SSHAgent.m (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/AgentController.m
r80 r83 609 609 if([agent isRunning]) 610 610 { 611 [agentPID setIntValue:[agent pid]];611 [agentPID setIntValue:[agent PID]]; 612 612 [agentGlobalAuthSocket setStringValue:[agent socketPath]]; 613 613 [agentLocalAuthSocket setStringValue:[agent agentSocketPath]]; trunk/Libs/SSHAgent.h
r82 r83 3 3 @interface SSHAgent : NSObject 4 4 { 5 int theP id;5 int thePID; 6 6 int s; 7 7 … … 15 15 NSLock *agentSocketPathLock; 16 16 NSLock *keysOnAgentLock; 17 NSLock *theP idLock;17 NSLock *thePIDLock; 18 18 } 19 19 20 20 + (id)currentAgent; 21 21 22 - ( BOOL)setSocketPath:(NSString *)path;22 - (void)setSocketPath:(NSString *)path; 23 23 24 24 - (NSString *)socketPath; … … 29 29 30 30 - (BOOL)isRunning; 31 - (int) pid;31 - (int)PID; 32 32 - (NSArray *)keysOnAgent; 33 33 trunk/Libs/SSHAgent.m
r82 r83 55 55 agentSocketPathLock = [[NSLock alloc] init]; 56 56 keysOnAgentLock = [[NSLock alloc] init]; 57 theP idLock = [[NSLock alloc] init];57 thePIDLock = [[NSLock alloc] init]; 58 58 59 59 return self; … … 67 67 [agentSocketPathLock dealloc]; 68 68 [keysOnAgentLock dealloc]; 69 [theP idLock dealloc];69 [thePIDLock dealloc]; 70 70 71 71 [super dealloc]; … … 73 73 74 74 /* Set the socket location for us to bind to. */ 75 - ( BOOL)setSocketPath:(NSString *)path76 { 77 if ([self isRunning] == YES)75 - (void)setSocketPath:(NSString *)path 76 { 77 if ([self isRunning]) 78 78 { 79 79 NSLog(@"setSocketPath: can't change path while the agent is running."); 80 return NO;80 return; 81 81 } 82 82 83 83 [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]; 93 87 [socketPathLock unlock]; 94 95 return YES;96 88 } 97 89 … … 99 91 - (NSString *)socketPath 100 92 { 101 NSString *returnString = nil;102 103 93 [socketPathLock lock]; 104 105 if(socketPath) 106 { 107 returnString = [NSString stringWithString:socketPath]; 108 } 109 94 NSString *returnString = [[socketPath copy] autorelease]; 110 95 [socketPathLock unlock]; 111 96 112 97 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]; 113 108 } 114 109 … … 116 111 - (NSString *)agentSocketPath 117 112 { 118 NSString *returnString = nil;119 120 113 [agentSocketPathLock lock]; 121 122 if(agentSocketPath) 123 { 124 returnString = [NSString stringWithString:agentSocketPath]; 125 } 126 114 NSString *returnString = [[agentSocketPath copy] autorelease]; 127 115 [agentSocketPathLock unlock]; 128 116 129 117 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]; 130 161 } 131 162 … … 139 170 140 171 /* If the PID is > 0, the agent should (in theory) be running. */ 141 if([self pid] > 0)172 if([self PID] > 0) 142 173 { 143 174 NSLog(@"Agent is already started"); … … 195 226 if ([@"SSH_AGENT_PID" isEqualToString:[columns objectAtIndex:1]]) 196 227 { 197 [theP idLock lock];198 theP id= [[columns objectAtIndex:2] intValue];199 [theP idLock unlock];228 [thePIDLock lock]; 229 thePID = [[columns objectAtIndex:2] intValue]; 230 [thePIDLock unlock]; 200 231 } 201 232 } 202 233 203 234 /* 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))) 205 236 { 206 237 NSLog(@"SSHAgent start: ssh-agent didn't give the output we expected"); … … 210 241 211 242 /* If there's no PID just return -1. */ 212 if([self pid] < 1)243 if([self PID] < 1) 213 244 { 214 245 NSLog(@"SSHAgent start: ssh-agent didn't give the output we expected"); … … 231 262 { 232 263 /* We can't stop something if we haven't got the pid. */ 233 if([self pid] > 0)264 if([self PID] > 0) 234 265 { 235 266 /* 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); 237 268 238 269 [agentSocketPathLock lock]; … … 243 274 [self closeSockets]; 244 275 245 [theP idLock lock];246 theP id= 0;247 [theP idLock unlock];276 [thePIDLock lock]; 277 thePID = 0; 278 [thePIDLock unlock]; 248 279 249 280 [keysOnAgentLock lock]; … … 256 287 257 288 return YES; 258 }259 260 /* Return YES if the agent is (in theory) running, and NO if not. */261 - (BOOL)isRunning262 {263 if([self pid] > 0) { return YES; }264 else { return NO; }265 }266 267 /* Get the pid. */268 - (int)pid269 {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 *)keysOnAgent281 {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;294 289 } 295 290 … … 640 635 { 641 636 keychain = [SSHKeychain currentKeychain]; 642 643 637 if ([keychain count] > 0) 644 638 [keychain addKeysToAgent]; … … 655 649 { 656 650 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 657 int currentPID = [self pid];651 int currentPID = [self PID]; 658 652 while (getpgid(currentPID) != -1) 659 653 { … … 665 659 we were monitoring will no longer exist. Exit early to avoid notifying the user that the old 666 660 agent is gone */ 667 if (currentPID != [self pid])661 if (currentPID != [self PID]) 668 662 { 669 663 [pool release]; … … 715 709 716 710 /* If the PID is < 1, we assume the agent isn't running. */ 717 if([self pid] < 1)711 if([self PID] < 1) 718 712 { 719 713 return nil;
