From 1f211163b9ba3e63abfc9c1f25753c8e370b8f84 Mon Sep 17 00:00:00 2001
From: Daniel Albers <daniel@lbers.com>
Date: Tue, 19 May 2009 00:29:33 +0200
Subject: [PATCH] Disable crashhandler if coredumps are enabled

---
 src/common/quassel.cpp |   24 +++++++++++++++++++-----
 1 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/src/common/quassel.cpp b/src/common/quassel.cpp
index 4be4db1..69059d6 100644
--- a/src/common/quassel.cpp
+++ b/src/common/quassel.cpp
@@ -22,6 +22,9 @@
 
 #include <iostream>
 #include <signal.h>
+#ifndef Q_OS_WIN32
+#include <sys/resource.h>
+#endif
 
 #include <QCoreApplication>
 #include <QDateTime>
@@ -55,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
 }
 
-- 
1.6.0.4

