aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPSSHTunnel.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2010-04-15 00:14:48 +0000
committerrowanbeentje <rowan@beent.je>2010-04-15 00:14:48 +0000
commit771c3ff3aa15188771881e2447d491b359d4c5da (patch)
treed5071fc81078bde2c9b82fee217b0f39463b7959 /Source/SPSSHTunnel.m
parenta7fb2c45dcdc8a08775e5bd8c77fa15612955d44 (diff)
downloadsequelpro-771c3ff3aa15188771881e2447d491b359d4c5da.tar.gz
sequelpro-771c3ff3aa15188771881e2447d491b359d4c5da.tar.bz2
sequelpro-771c3ff3aa15188771881e2447d491b359d4c5da.zip
- Add locking for SSH debug message processing - this addresses http://spbug.com/l/117
Diffstat (limited to 'Source/SPSSHTunnel.m')
-rw-r--r--Source/SPSSHTunnel.m14
1 files changed, 12 insertions, 2 deletions
diff --git a/Source/SPSSHTunnel.m b/Source/SPSSHTunnel.m
index dfeb2f16..eeef83d2 100644
--- a/Source/SPSSHTunnel.m
+++ b/Source/SPSSHTunnel.m
@@ -56,6 +56,7 @@
stateChangeSelector = nil;
lastError = nil;
debugMessages = [[NSMutableArray alloc] init];
+ debugMessagesLock = [[NSLock alloc] init];
answerAvailableLock = [[NSLock alloc] init];
// Set up a connection for use by the tunnel process
@@ -164,7 +165,10 @@
* by line endings.
*/
- (NSString *) debugMessages {
- return [debugMessages componentsJoinedByString:@"\n"];
+ [debugMessagesLock lock];
+ NSString *debugMessagesString = [debugMessages componentsJoinedByString:@"\n"];
+ [debugMessagesLock unlock];
+ return debugMessagesString;
}
/*
@@ -175,7 +179,9 @@
localPort = 0;
if (connectionState != PROXY_STATE_IDLE) return;
+ [debugMessagesLock lock];
[debugMessages removeAllObjects];
+ [debugMessagesLock unlock];
[NSThread detachNewThreadSelector:@selector(launchTask:) toTarget: self withObject: nil ];
}
@@ -369,7 +375,8 @@
}
/*
- * Processes messages recieved from the SSH task
+ * Processes messages recieved from the SSH task. These may be received singly
+ * or several stuck together.
*/
- (void)standardErrorHandler:(NSNotification*)aNotification
{
@@ -385,7 +392,9 @@
enumerator = [messages objectEnumerator];
while (message = [[enumerator nextObject] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]) {
if (![message length]) continue;
+ [debugMessagesLock lock];
[debugMessages addObject:[NSString stringWithString:message]];
+ [debugMessagesLock unlock];
if ([message rangeOfString:@"Entering interactive session."].location != NSNotFound) {
connectionState = PROXY_STATE_CONNECTED;
@@ -625,6 +634,7 @@
[tunnelConnection invalidate];
[tunnelConnection release];
[debugMessages release];
+ [debugMessagesLock release];
[answerAvailableLock tryLock];
[answerAvailableLock unlock];
[answerAvailableLock release];