Fixes #682 - Core crashes on client connection
[quassel.git] / src / common / quassel.cpp
index 50651bd..33b6cbd 100644 (file)
 
 #include "quassel.h"
 
+#include <iostream>
 #include <signal.h>
+#if !defined Q_OS_WIN32 && !defined Q_OS_MAC
+#  include <sys/resource.h>
+#endif
 
 #include <QCoreApplication>
 #include <QDateTime>
@@ -54,11 +58,22 @@ Quassel::Quassel() {
   // we have crashhandler for win32 and unix (based on execinfo).
   // on mac os we use it's integrated backtrace generator
 #if defined(Q_OS_WIN32) || (defined(HAVE_EXECINFO) && !defined(Q_OS_MAC))
-  signal(SIGABRT, handleSignal);
-  signal(SIGSEGV, handleSignal);
-#  ifndef Q_OS_WIN32
-  signal(SIGBUS, handleSignal);
-#  endif
+
+# ifndef Q_OS_WIN32
+  // we only handle crashes ourselves if coredumps are disabled
+  struct rlimit *limit = (rlimit *) malloc(sizeof(struct rlimit));
+  int rc = getrlimit(RLIMIT_CORE, limit);
+
+  if(rc == -1 || !((long)limit->rlim_cur > 0 || limit->rlim_cur == RLIM_INFINITY)) {
+# endif
+    signal(SIGABRT, handleSignal);
+    signal(SIGSEGV, handleSignal);
+#   ifndef Q_OS_WIN32
+    signal(SIGBUS, handleSignal);
+  }
+  free(limit);
+#   endif
+
 #endif
 }
 
@@ -84,6 +99,11 @@ bool Quassel::init() {
     return false;
   }
 
+  if(isOptionSet("version")) {
+    std::cout << qPrintable("Quassel IRC: " + Quassel::buildInfo().plainVersionString) << std::endl;
+    return false;
+  }
+
   DEBUG = isOptionSet("debug");
   return true;
 }
@@ -336,6 +356,13 @@ QString Quassel::findDataFilePath(const QString &fileName) {
   return QString();
 }
 
+QStringList Quassel::scriptDirPaths() {
+  QStringList res(configDirPath() + "scripts/");
+  foreach(QString path, dataDirPaths())
+    res << path + "scripts/";
+  return res;
+}
+
 QString Quassel::translationDirPath() {
   if(_translationDirPath.isEmpty()) {
     // We support only one translation dir; fallback mechanisms wouldn't work else.