Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for SIGTERM #472

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
24 changes: 24 additions & 0 deletions Tests/KSCrashRecordingTests/KSCrashDoctor_Tests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#import <XCTest/XCTest.h>

#import "KSCrashDoctor.h"
#import "KSTestModuleConfig.h"

@interface KSCrashDoctor_Tests : XCTestCase @end

@implementation KSCrashDoctor_Tests

- (NSDictionary<NSString *, id> *)_crashReportAsJSON:(NSString *)filename
{
NSURL *url = [KS_TEST_MODULE_BUNDLE 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
7 changes: 1 addition & 6 deletions Tests/KSCrashRecordingTests/KSCrashReportFixer_Tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@

#import <XCTest/XCTest.h>
#import "KSCrashReportFixer.h"

#ifdef SWIFTPM_MODULE_BUNDLE
#define KS_TEST_MODULE_BUNDLE SWIFTPM_MODULE_BUNDLE
#else
#define KS_TEST_MODULE_BUNDLE ([NSBundle bundleForClass:[self class]])
#endif
#import "KSTestModuleConfig.h"

@interface KSCrashReportFixer_Tests : XCTestCase

Expand Down
Loading