2 * Adium is the legal property of its developers, whose names are listed in the copyright file included
3 * with this source distribution.
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11 * Public License for more details.
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 Catches application crashes and forwards them to the crash reporter application
21 #import "AICrashController.h"
22 #import "AICrashReporter.h"
23 #import <AIUtilities/AIFileManagerAdditions.h>
25 void CrashHandler_Signal(int i);
27 //Enable crash catching for the crash reporter
28 static AICrashController *sharedCrashController = nil;
30 @implementation AICrashController
32 + (void)enableCrashCatching
34 if (!sharedCrashController) {
35 sharedCrashController = [[AICrashController alloc] init];
42 if ((self = [super init])) {
43 //Remove any existing crash logs
44 [[NSFileManager defaultManager] trashFileAtPath:[[NSString stringWithFormat:@"~/Library/Logs/CrashReporter/%@.crash.log", \
45 [[NSProcessInfo processInfo] processName]] stringByExpandingTildeInPath]];
47 //Install custom handlers which properly terminate this application if one is received
48 signal(SIGILL, CrashHandler_Signal); /* 4: illegal instruction (not reset when caught) */
49 signal(SIGTRAP, CrashHandler_Signal); /* 5: trace trap (not reset when caught) */
50 signal(SIGEMT, CrashHandler_Signal); /* 7: EMT instruction */
51 signal(SIGFPE, CrashHandler_Signal); /* 8: floating point exception */
52 signal(SIGBUS, CrashHandler_Signal); /* 10: bus error */
53 signal(SIGSEGV, CrashHandler_Signal); /* 11: segmentation violation */
54 signal(SIGSYS, CrashHandler_Signal); /* 12: bad argument to system call */
55 signal(SIGXCPU, CrashHandler_Signal); /* 24: exceeded CPU time limit */
56 signal(SIGXFSZ, CrashHandler_Signal); /* 25: exceeded file size limit */
58 //I think SIGABRT is an exception... we should ignore it.
59 signal(SIGABRT, SIG_IGN);
67 //When a signal occurs, load the crash reporter and close this application
68 void CrashHandler_Signal(int i)
70 NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
71 NSString *crashReporterPath = [bundlePath stringByAppendingPathComponent:RELATIVE_PATH_TO_CRASH_REPORTER];
73 [[NSWorkspace sharedWorkspace] openFile:bundlePath withApplication:crashReporterPath];