Implemented a signal handler to graceful shutdown Quassel when SIGTERM or
[quassel.git] / src / common / main.cpp
index c53daab..86d874b 100644 (file)
  ***************************************************************************/
 
 #include "settings.h"
+#include <QString>
 
 #if defined BUILD_CORE
 #include <QCoreApplication>
+#include <QDir>
 #include "core.h"
 
 #elif defined BUILD_QTGUI
 #error "Something is wrong - you need to #define a build mode!"
 #endif
 
+#include <signal.h>
+
+//! Signal handler for graceful shutdown.
+void handle_signal(int sig) {
+  qWarning(QString("Caught signal %1 - exiting.").arg(sig).toAscii());
+  QCoreApplication::quit();
+}
+
 int main(int argc, char **argv) {
+  // We catch SIGTERM and SIGINT (caused by Ctrl+C) to graceful shutdown Quassel.
+  signal(SIGTERM, handle_signal);
+  signal(SIGINT, handle_signal);
+
+  qRegisterMetaType<Message>("Message");
+  qRegisterMetaType<BufferId>("BufferId");
+  qRegisterMetaTypeStreamOperators<Message>("Message");
+  qRegisterMetaTypeStreamOperators<BufferId>("BufferId");
+
 #if defined BUILD_CORE
   Global::runMode = Global::CoreOnly;
   QCoreApplication app(argc, argv);
@@ -64,7 +83,7 @@ int main(int argc, char **argv) {
   Core::instance();  // create and init the core
 #endif
 
-  Settings::init();
+  //Settings::init();
 
 #ifndef BUILD_CORE
   Style::init();