main_nix.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <iostream>
00029 #include <signal.h>
00030
00031 #include <QApplication>
00032
00033 #define BASE_QM "scribus"
00034
00035 #include "scribusapp.h"
00036 #include "scribuscore.h"
00037 #include "scribus.h"
00038
00039 #include "scconfig.h"
00040
00041 int mainApp(int argc, char **argv);
00042 void initCrashHandler();
00043 static void defaultCrashHandler(int sig);
00044
00045 ScribusCore SCRIBUS_API *ScCore;
00046 ScribusMainWindow SCRIBUS_API *ScMW;
00047 ScribusQApp SCRIBUS_API *ScQApp;
00048 bool emergencyActivated;
00049
00050 int main(int argc, char *argv[])
00051 {
00052 return mainApp(argc, argv);
00053 }
00054
00065 int mainApp(int argc, char **argv)
00066 {
00067 emergencyActivated=false;
00068 ScribusQApp app(argc, argv);
00069 initCrashHandler();
00070 app.parseCommandLine();
00071 if (app.useGUI)
00072 {
00073 int appRetVal=app.init();
00074 if (appRetVal==EXIT_FAILURE)
00075 return(EXIT_FAILURE);
00076 return app.exec();
00077 }
00078 return EXIT_SUCCESS;
00079 }
00080
00081 void initCrashHandler()
00082 {
00083 typedef void (*HandlerType)(int);
00084 HandlerType handler = 0;
00085 handler = defaultCrashHandler;
00086 if (!handler)
00087 handler = SIG_DFL;
00088 sigset_t mask;
00089 sigemptyset(&mask);
00090 #ifdef SIGSEGV
00091 signal (SIGSEGV, handler);
00092 sigaddset(&mask, SIGSEGV);
00093 #endif
00094 #ifdef SIGFPE
00095 signal (SIGFPE, handler);
00096 sigaddset(&mask, SIGFPE);
00097 #endif
00098 #ifdef SIGILL
00099 signal (SIGILL, handler);
00100 sigaddset(&mask, SIGILL);
00101 #endif
00102 #ifdef SIGABRT
00103 signal (SIGABRT, handler);
00104 sigaddset(&mask, SIGABRT);
00105 #endif
00106 sigprocmask(SIG_UNBLOCK, &mask, 0);
00107 }
00108
00109 void defaultCrashHandler(int sig)
00110 {
00111 static int crashRecursionCounter = 0;
00112 crashRecursionCounter++;
00113 signal(SIGALRM, SIG_DFL);
00114 if (crashRecursionCounter < 2)
00115 {
00116 emergencyActivated=true;
00117 crashRecursionCounter++;
00118 QString sigHdr=QObject::tr("Scribus Crash");
00119 QString sigLine="-------------";
00120 QString sigMsg=QObject::tr("Scribus crashes due to Signal #%1").arg(sig);
00121 std::cout << sigHdr.toStdString() << std::endl;
00122 std::cout << sigLine.toStdString() << std::endl;
00123 std::cout << sigMsg.toStdString() << std::endl;
00124 if (ScribusQApp::useGUI)
00125 {
00126 ScCore->closeSplash();
00127 QMessageBox::critical(ScMW, sigHdr, sigMsg, QObject::tr("&OK"));
00128 ScMW->emergencySave();
00129 ScMW->close();
00130 }
00131 alarm(300);
00132 }
00133 exit(255);
00134 }