1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include "MrsWatson.h"
#include "logging/ErrorReporter.h"
#include "logging/EventLogger.h"
// This must be global so that in case of a crash or signal, we can still generate
// a complete error report with a reference
static ErrorReporter gErrorReporter = NULL;
static void handleSignal(int signum)
{
logCritical("Sent signal %d, exiting", signum);
if (gErrorReporter != NULL && gErrorReporter->started) {
errorReporterClose(gErrorReporter);
} else {
logPossibleBug("MrsWatson (or one of its hosted plugins) has encountered a serious error and crashed.");
}
exit(RETURN_CODE_SIGNAL + signum);
}
int main(int argc, char *argv[])
{
gErrorReporter = newErrorReporter();
// Set up signal handling only after logging is initialized. If we crash before
// here, something is seriously wrong.
#ifdef SIGHUP
signal(SIGHUP, handleSignal);
#endif
#ifdef SIGINT
signal(SIGINT, handleSignal);
#endif
#ifdef SIGQUIT
signal(SIGQUIT, handleSignal);
#endif
#ifdef SIGILL
signal(SIGILL, handleSignal);
#endif
#ifdef SIGABRT
signal(SIGABRT, handleSignal);
#endif
#ifdef SIGFPE
signal(SIGFPE, handleSignal);
#endif
#ifdef SIGKILL
signal(SIGKILL, handleSignal);
#endif
#ifdef SIGBUS
signal(SIGBUS, handleSignal);
#endif
#ifdef SIGSEGV
signal(SIGSEGV, handleSignal);
#endif
#ifdef SIGSYS
signal(SIGSYS, handleSignal);
#endif
#ifdef SIGPIPE
signal(SIGPIPE, handleSignal);
#endif
#ifdef SIGTERM
signal(SIGTERM, handleSignal);
#endif
return mrsWatsonMain(gErrorReporter, argc, argv);
}
|