Skip to content

Commit

Permalink
fix: multiple console log redirection, causes crash
Browse files Browse the repository at this point in the history
  • Loading branch information
rob2468 committed Apr 4, 2020
1 parent c38ce52 commit 0d44ccf
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions Classes/Core/Component/HSDConsoleLogComponent.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,16 @@ - (void)redirectReadCompletionNotificationReceived:(NSNotification *)notificatio
#pragma mark - state

- (BOOL)isRedirected {
BOOL isRedirected;
if (self.stdErrFd == kStdErrIllegalFd) {
isRedirected = NO;
} else {
isRedirected = YES;
}
return isRedirected;
return self.stdErrFd != kStdErrIllegalFd;
}

#pragma mark -

- (void)redirectStandardErrorOutput {
if ([self isRedirected]) {
return;
}

// save origin STDERR_FILENO with a new file descriptor
self.stdErrFd = dup(STDERR_FILENO);

Expand All @@ -84,6 +82,10 @@ - (void)redirectStandardErrorOutput {
}

-(void)recoverStandardErrorOutput {
if (![self isRedirected]) {
return;
}

// remove observer
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSFileHandleReadCompletionNotification object:nil];

Expand Down

0 comments on commit 0d44ccf

Please sign in to comment.