Skip to content

Commit

Permalink
Added support for SIGTERM
Browse files Browse the repository at this point in the history
  • Loading branch information
naftaly committed May 7, 2024
1 parent cc4eff4 commit 8217d6b
Show file tree
Hide file tree
Showing 5 changed files with 2,619 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Source/KSCrash-Tests/KSCrashDoctor_Tests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#import <XCTest/XCTest.h>

#import "KSCrashDoctor.h"

@interface KSCrashDoctor_Tests : XCTestCase @end


@implementation KSCrashDoctor_Tests

- (NSDictionary<NSString *, id> *)_crashReportAsJSON:(NSString *)filename
{
NSURL *url = [[NSBundle bundleForClass:self.class] URLForResource:filename withExtension:@"json"];
NSData *data = [NSData dataWithContentsOfURL:url];
return [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
}

- (void) testGracefulTermination
{
id report = [self _crashReportAsJSON:@"sigterm"];
NSString *diagnostic = [[[KSCrashDoctor alloc] init] diagnoseCrash:report];
XCTAssertEqual(diagnostic, @"The OS request the app be gracefully terminated.");
}

@end
9 changes: 9 additions & 0 deletions Sources/KSCrashRecording/KSCrashDoctor.m
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,11 @@ - (NSString*) appendOriginatingCall:(NSString*) string callName:(NSString*) call
return string;
}

- (BOOL) isGracefulTerminationRequest:(NSDictionary *)report
{
return [report[@KSCrashField_Signal][@KSCrashField_Signal] integerValue] == SIGTERM;
}

- (NSString*) diagnoseCrash:(NSDictionary*) report
{
@try
Expand Down Expand Up @@ -558,6 +563,10 @@ - (NSString*) diagnoseCrash:(NSDictionary*) report
callName:lastFunctionName];
}

if([self isGracefulTerminationRequest:errorReport]) {
return @"The OS request the app be gracefully terminated.";
}

return nil;
}
@catch (NSException* e)
Expand Down
2 changes: 2 additions & 0 deletions Sources/KSCrashRecordingCore/KSSignalInfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ static const KSSignalInfo g_fatalSignalData[] =
SIGNAL_INFO(SIGSEGV, g_sigSegVCodes),
SIGNAL_INFO_NOCODES(SIGSYS),
SIGNAL_INFO(SIGTRAP, g_sigTrapCodes),
SIGNAL_INFO_NOCODES(SIGTERM),
};
static const int g_fatalSignalsCount = sizeof(g_fatalSignalData) / sizeof(*g_fatalSignalData);

Expand All @@ -131,6 +132,7 @@ static const int g_fatalSignals[] =
SIGSEGV,
SIGSYS,
SIGTRAP,
SIGTERM,
};

const char* kssignal_signalName(const int sigNum)
Expand Down
Loading

0 comments on commit 8217d6b

Please sign in to comment.