Skip to content
Snippets Groups Projects
Commit 82b8ac00 authored by George Nachman's avatar George Nachman
Browse files

Add locks to use of logHandle in PTYTask to fix race conditions.

parent de5a12f3
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -404,7 +404,9 @@ setup_tty_param(
fd = -1;
tty = nil;
logPath = nil;
logHandle = nil;
@synchronized(logHandle) {
logHandle = nil;
}
hasOutput = NO;
 
writeBuffer = [[NSMutableData alloc] init];
Loading
Loading
@@ -640,8 +642,10 @@ static void reapchild(int n)
#if DEBUG_METHOD_TRACE
NSLog(@"%s(%d):-[PTYTask readTask:%@]", __FILE__, __LINE__, data);
#endif
if ([self logging]) {
[logHandle writeData:data];
@synchronized(logHandle) {
if ([self logging]) {
[logHandle writeData:data];
}
}
 
// forward the data to our delegate
Loading
Loading
@@ -740,35 +744,41 @@ static void reapchild(int n)
 
- (BOOL)loggingStartWithPath:(NSString*)aPath
{
[logPath autorelease];
logPath = [[aPath stringByStandardizingPath] copy];
@synchronized(logHandle) {
[logPath autorelease];
logPath = [[aPath stringByStandardizingPath] copy];
 
[logHandle autorelease];
logHandle = [NSFileHandle fileHandleForWritingAtPath:logPath];
if (logHandle == nil) {
NSFileManager* fm = [NSFileManager defaultManager];
[fm createFileAtPath:logPath contents:nil attributes:nil];
[logHandle autorelease];
logHandle = [NSFileHandle fileHandleForWritingAtPath:logPath];
}
[logHandle retain];
[logHandle seekToEndOfFile];
if (logHandle == nil) {
NSFileManager* fm = [NSFileManager defaultManager];
[fm createFileAtPath:logPath contents:nil attributes:nil];
logHandle = [NSFileHandle fileHandleForWritingAtPath:logPath];
}
[logHandle retain];
[logHandle seekToEndOfFile];
 
return logHandle == nil ? NO : YES;
return logHandle == nil ? NO : YES;
}
}
 
- (void)loggingStop
{
[logHandle closeFile];
@synchronized(logHandle) {
[logHandle closeFile];
 
[logPath autorelease];
[logHandle autorelease];
logPath = nil;
logHandle = nil;
[logPath autorelease];
[logHandle autorelease];
logPath = nil;
logHandle = nil;
}
}
 
- (BOOL)logging
{
return logHandle == nil ? NO : YES;
@synchronized(logHandle) {
return logHandle == nil ? NO : YES;
}
}
 
- (NSString*)description
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment