Merged [15040]: Trying some magic: 5 seconds after the last unreachable host is repor...
[adiumx.git] / Source / AICrashController.m
blobbff237a12f36a53149d7318ce13237ab826c1bae
1 /*
2  * Adium is the legal property of its developers, whose names are listed in the copyright file included
3  * with this source distribution.
4  *
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.
8  *
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.
12  *
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.
15  */
18  Catches application crashes and forwards them to the crash reporter application
19  */
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];
36         }
39 //Init
40 - (id)init
42         if((self = [super init])){
43                 //Remove any existing crash logs
44                 [[NSFileManager defaultManager] trashFileAtPath:CRASHES_PATH];
46                 //Install custom handlers which properly terminate this application if one is received
47                 signal(SIGILL,  CrashHandler_Signal);   /* 4:   illegal instruction (not reset when caught) */
48                 signal(SIGTRAP, CrashHandler_Signal);   /* 5:   trace trap (not reset when caught) */
49                 signal(SIGEMT,  CrashHandler_Signal);   /* 7:   EMT instruction */
50                 signal(SIGFPE,  CrashHandler_Signal);   /* 8:   floating point exception */
51                 signal(SIGBUS,  CrashHandler_Signal);   /* 10:  bus error */
52                 signal(SIGSEGV, CrashHandler_Signal);   /* 11:  segmentation violation */
53                 signal(SIGSYS,  CrashHandler_Signal);   /* 12:  bad argument to system call */
54                 signal(SIGXCPU, CrashHandler_Signal);   /* 24:  exceeded CPU time limit */
55                 signal(SIGXFSZ, CrashHandler_Signal);   /* 25:  exceeded file size limit */
57                 //I think SIGABRT is an exception... we should ignore it.
58                 signal(SIGABRT, SIG_IGN);
59         }
61         return self;
64 @end
66 //When a signal occurs, load the crash reporter and close this application
67 void CrashHandler_Signal(int i)
69         NSString        *bundlePath = [[[NSBundle mainBundle] bundlePath] stringByExpandingTildeInPath];
70         NSString        *crashReporterPath = [bundlePath stringByAppendingPathComponent:RELATIVE_PATH_TO_CRASH_REPORTER];
72         [[NSWorkspace sharedWorkspace] openFile:bundlePath withApplication:crashReporterPath];
74         exit(-1);