diff options
Diffstat (limited to 'main/MrsWatsonMain.c')
| -rw-r--r-- | main/MrsWatsonMain.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/main/MrsWatsonMain.c b/main/MrsWatsonMain.c new file mode 100644 index 0000000..71063ee --- /dev/null +++ b/main/MrsWatsonMain.c @@ -0,0 +1,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); +} |
