aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Vrátil <dvratil@kde.org>2016-09-06 12:44:03 (GMT)
committerDaniel Vrátil <dvratil@kde.org>2016-09-06 12:46:49 (GMT)
commit769fe236f43293afdee00dd58687b820e20dd1fd (patch)
treee5f33416ff8e6e5fccbae9bd9371f392b8264c3e
parentd2a2fcb3eb7d286cb09ac1ae6642f9f245e1d904 (diff)
Enable KCrash in Akonadi Server
Move away from custom akCrash handler (using backtrace()) to using DrKonqi. This will allow users to report crashes in Akonadi Server easilly.
-rw-r--r--CMakeLists.txt7
-rw-r--r--cmake/modules/FindBacktrace.cmake84
-rw-r--r--config-akonadi.h.cmake5
-rw-r--r--src/akonadicontrol/main.cpp5
-rw-r--r--src/server/connection.cpp4
-rw-r--r--src/server/main.cpp11
-rw-r--r--src/shared/CMakeLists.txt3
-rw-r--r--src/shared/akcrash.cpp152
-rw-r--r--src/shared/akcrash.h39
-rw-r--r--src/shared/akdebug.cpp5
10 files changed, 10 insertions, 305 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 070b7ac..4f34165 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -55,6 +55,7 @@ find_package(KF5KIO ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5WidgetsAddons ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5WindowSystem ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5XmlGui ${KF5_VERSION} CONFIG REQUIRED)
+find_package(KF5Crash ${KF5_VERSION} CONFIG REQUIRED)
find_package(Qt5Designer NO_MODULE)
set_package_properties(Qt5Designer PROPERTIES
@@ -149,12 +150,6 @@ if(AKONADI_BUILD_QSQLITE)
)
endif()
-find_package(Backtrace)
-if(Backtrace_FOUND)
- include_directories(${Backtrace_INCLUDE_DIRS})
- add_definitions(-DHAVE_BACKTRACE)
-endif()
-
find_program(XMLLINT_EXECUTABLE xmllint)
if(NOT XMLLINT_EXECUTABLE)
message(STATUS "xmllint not found, skipping akonadidb.xml schema validation")
diff --git a/cmake/modules/FindBacktrace.cmake b/cmake/modules/FindBacktrace.cmake
deleted file mode 100644
index 0af8d1b..0000000
--- a/cmake/modules/FindBacktrace.cmake
+++ /dev/null
@@ -1,84 +0,0 @@
-# - Find provider for backtrace(3)
-# Checks if OS supports backtrace(3) via either libc or custom library.
-# This module defines the following variables:
-# Backtrace_HEADER - The header file needed for backtrace(3). Cached.
-# Could be forcibly set by user.
-# Backtrace_INCLUDE_DIRS - The include directories needed to use backtrace(3) header.
-# Backtrace_LIBRARIES - The libraries (linker flags) needed to use backtrace(3), if any.
-# Backtrace_FOUND - Is set if and only if backtrace(3) support detected.
-#
-# The following cache variables are also available to set or use:
-# Backtrace_LIBRARY - The external library providing backtrace, if any.
-# Backtrace_INCLUDE_DIR - The directory holding the backtrace(3) header.
-#
-# Typical usage is to generate of header file using configure_file() with the
-# contents like the following:
-# #cmakedefine01 Backtrace_FOUND
-# #if Backtrace_FOUND
-# # include <${Backtrace_HEADER}>
-# #endif
-# And then reference that generated header file in actual source.
-
-#=============================================================================
-# Copyright (c) 2013, Vadim Zhukov <persgray@gmail.com>
-#
-# Permission to use, copy, modify, and distribute this software for any
-# purpose with or without fee is hereby granted, provided that the above
-# copyright notice and this permission notice appear in all copies.
-#
-# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-
-include(CMakePushCheckState)
-include(CheckSymbolExists)
-include(FindPackageHandleStandardArgs)
-
-# List of variables to be provided to find_package_handle_standard_args()
-set(_Backtrace_STD_ARGS Backtrace_INCLUDE_DIR)
-
-if(Backtrace_HEADER)
- set(_Backtrace_HEADER_TRY "${Backtrace_HEADER}")
-else(Backtrace_HEADER)
- set(_Backtrace_HEADER_TRY "execinfo.h")
-endif(Backtrace_HEADER)
-
-find_path(Backtrace_INCLUDE_DIR "${_Backtrace_HEADER_TRY}")
-set(Backtrace_INCLUDE_DIRS ${Backtrace_INCLUDE_DIR})
-
-# First, check if we already have backtrace(), e.g., in libc
-cmake_push_check_state(RESET)
-set(CMAKE_REQUIRED_INCLUDES ${Backtrace_INCLUDE_DIRS})
-check_symbol_exists("backtrace" "${_Backtrace_HEADER_TRY}" _Backtrace_SYM_FOUND)
-cmake_pop_check_state()
-
-if(_Backtrace_SYM_FOUND)
- set(Backtrace_LIBRARY)
- if(NOT Backtrace_FIND_QUIETLY)
- message(STATUS "backtrace facility detected in default set of libraries")
- endif()
-else()
- # Check for external library, for non-glibc systems
- if(Backtrace_INCLUDE_DIR)
- # OpenBSD has libbacktrace renamed to libexecinfo
- find_library(Backtrace_LIBRARY "execinfo")
- elseif() # respect user wishes
- set(_Backtrace_HEADER_TRY "backtrace.h")
- find_path(Backtrace_INCLUDE_DIR ${_Backtrace_HEADER_TRY})
- find_library(Backtrace_LIBRARY "backtrace")
- endif()
-
- # Prepend list with library path as it's more common practice
- set(_Backtrace_STD_ARGS Backtrace_LIBRARY ${_Backtrace_STD_ARGS})
-endif()
-
-set(Backtrace_LIBRARIES ${Backtrace_LIBRARY})
-set(Backtrace_HEADER "${_Backtrace_HEADER_TRY}" CACHE STRING "Header providing backtrace(3) facility")
-
-find_package_handle_standard_args(Backtrace FOUND_VAR Backtrace_FOUND REQUIRED_VARS ${_Backtrace_STD_ARGS})
-mark_as_advanced(Backtrace_HEADER Backtrace_INCLUDE_DIR Backtrace_LIBRARY)
diff --git a/config-akonadi.h.cmake b/config-akonadi.h.cmake
index 60ac9b0..53e36fc 100644
--- a/config-akonadi.h.cmake
+++ b/config-akonadi.h.cmake
@@ -1,8 +1,3 @@
-#cmakedefine01 Backtrace_FOUND
-#if Backtrace_FOUND
-# include <@Backtrace_HEADER@>
-#endif
-
#cmakedefine HAVE_UNISTD_H 1
#cmakedefine HAVE_MALLOC_TRIM 1
diff --git a/src/akonadicontrol/main.cpp b/src/akonadicontrol/main.cpp
index 003aa67..dd8510f 100644
--- a/src/akonadicontrol/main.cpp
+++ b/src/akonadicontrol/main.cpp
@@ -23,7 +23,6 @@
#include "akonadicontrol_debug.h"
#include <shared/akapplication.h>
-#include <shared/akcrash.h>
#include <private/dbus_p.h>
@@ -32,6 +31,8 @@
#include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusError>
+#include <KCrash/KCrash>
+
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
@@ -76,7 +77,7 @@ int main(int argc, char **argv)
new ControlManager;
sAgentManager = new AgentManager(app.commandLineArguments().isSet(QStringLiteral("verbose")));
- AkonadiCrash::setEmergencyMethod(crashHandler);
+ KCrash::setEmergencySaveFunction(crashHandler);
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
QGuiApplication::setFallbackSessionManagementEnabled(false);
diff --git a/src/server/connection.cpp b/src/server/connection.cpp
index 5a16a35..0344107 100644
--- a/src/server/connection.cpp
+++ b/src/server/connection.cpp
@@ -31,8 +31,6 @@
#include "tracer.h"
#include "collectionreferencemanager.h"
-#include <shared/akcrash.h>
-
#include <assert.h>
#include <private/protocol_p.h>
@@ -238,7 +236,7 @@ void Connection::slotNewData()
m_currentHandler->failureResponse(QString::fromUtf8(e.type()) + QLatin1String(": ") + QString::fromUtf8(e.what()));
}
} catch (...) {
- qCCritical(AKONADISERVER_LOG) << "Unknown exception caught: " << akBacktrace();
+ qCCritical(AKONADISERVER_LOG) << "Unknown exception caught in Connection for session" << m_sessionId;
if (m_currentHandler) {
m_currentHandler->failureResponse("Unknown exception caught");
}
diff --git a/src/server/main.cpp b/src/server/main.cpp
index c676c41..884227a 100644
--- a/src/server/main.cpp
+++ b/src/server/main.cpp
@@ -21,7 +21,6 @@
#include "akonadiserver_debug.h"
#include <shared/akapplication.h>
-#include <shared/akcrash.h>
#include <private/dbus_p.h>
@@ -39,14 +38,6 @@
Q_IMPORT_PLUGIN(qsqlite3)
#endif
-void shutdownHandler(int)
-{
- qCDebug(AKONADISERVER_LOG) << "Shutting down AkonadiServer...";
-
- Akonadi::Server::AkonadiServer::instance()->quit();
- exit(255);
-}
-
int main(int argc, char **argv)
{
Q_INIT_RESOURCE(akonadidb);
@@ -75,10 +66,10 @@ int main(int argc, char **argv)
// Make sure we do initialization from eventloop, otherwise
// org.freedesktop.Akonadi.upgrading service won't be registered to DBus at all
QTimer::singleShot(0, Akonadi::Server::AkonadiServer::instance(), &Akonadi::Server::AkonadiServer::init);
- AkonadiCrash::setShutdownMethod(shutdownHandler);
const int result = app.exec();
+ qCDebug(AKONADISERVER_LOG) << "Shutting down AkonadiServer...";
Akonadi::Server::AkonadiServer::instance()->quit();
Q_CLEANUP_RESOURCE(akonadidb);
diff --git a/src/shared/CMakeLists.txt b/src/shared/CMakeLists.txt
index 475ef05..92c0f5e 100644
--- a/src/shared/CMakeLists.txt
+++ b/src/shared/CMakeLists.txt
@@ -1,6 +1,5 @@
set(akonadi_shared_srcs
akapplication.cpp
- akcrash.cpp
akdebug.cpp
)
@@ -9,5 +8,5 @@ add_library(akonadi_shared STATIC ${akonadi_shared_srcs})
target_link_libraries(akonadi_shared
Qt5::Core
KF5AkonadiPrivate
- ${Backtrace_LIBRARIES}
+ KF5::Crash
)
diff --git a/src/shared/akcrash.cpp b/src/shared/akcrash.cpp
deleted file mode 100644
index f52ef1f..0000000
--- a/src/shared/akcrash.cpp
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * This file is part of the KDE Libraries
- * Copyright (C) 2000 Timo Hummel <timo.hummel@sap.com>
- * Tom Braun <braunt@fh-konstanz.de>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "akcrash.h"
-
-#include <QDebug>
-#include <QtCore/QString>
-
-#include <string.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#ifdef HAVE_BACKTRACE
-#include <execinfo.h>
-#endif
-
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#endif
-
-QString akBacktrace()
-{
- QString s;
-
- /* FIXME: is there an equivalent for darwin, *BSD, or windows? */
-#ifdef HAVE_BACKTRACE
- void *trace[256];
- int n = backtrace(trace, 256);
- if (!n) {
- return s;
- }
-
- char **strings = backtrace_symbols(trace, n);
-
- s = QStringLiteral("[\n");
-
- for (int i = 0; i < n; ++i) {
- s += QString::number(i) +
- QLatin1String(": ") +
- QLatin1String(strings[i]) + QLatin1String("\n");
- }
- s += QLatin1String("]\n");
-
- if (strings) {
- free(strings);
- }
-#endif
-
- return s;
-}
-
-static AkonadiCrash::HandlerType s_emergencyMethod = 0;
-static AkonadiCrash::HandlerType s_shutdownMethod = 0;
-static int recursionCount = 0;
-
-void AkonadiCrash::setEmergencyMethod(HandlerType method)
-{
- s_emergencyMethod = method;
-}
-
-void AkonadiCrash::setShutdownMethod(HandlerType method)
-{
- s_shutdownMethod = method;
-}
-
-static void defaultCrashHandler(int sig)
-{
- ++recursionCount;
- if (recursionCount <= 2) {
- if (sig != SIGTERM && sig != SIGINT) {
- if (recursionCount == 1) {
- qCritical("%s", qPrintable(akBacktrace()));
- } else { // fall back to something more simple in case the other one crashed itself
- fprintf(stderr, "%s", akBacktrace().toLatin1().data());
- }
-
- if (s_emergencyMethod) {
- s_emergencyMethod(sig);
- }
- } else {
- if (s_shutdownMethod) {
- s_shutdownMethod(sig);
- }
- }
- }
-#ifdef Q_CC_MINGW
- _Exit(255);
-#else
- _exit(255);
-#endif
-}
-
-void AkonadiCrash::init()
-{
- HandlerType handler = defaultCrashHandler;
-
-#if defined Q_OS_UNIX && !defined ENABLE_ASAN
- if (!handler) {
- handler = SIG_DFL;
- }
-
- sigset_t mask;
- sigemptyset(&mask);
-
-#ifdef SIGSEGV
- signal(SIGSEGV, handler);
- sigaddset(&mask, SIGSEGV);
-#endif
-#ifdef SIGFPE
- signal(SIGFPE, handler);
- sigaddset(&mask, SIGFPE);
-#endif
-#ifdef SIGILL
- signal(SIGILL, handler);
- sigaddset(&mask, SIGILL);
-#endif
-#ifdef SIGABRT
- signal(SIGABRT, handler);
- sigaddset(&mask, SIGABRT);
-#endif
-#ifdef SIGTERM
- signal(SIGTERM, handler);
- sigaddset(&mask, SIGTERM);
-#endif
-#ifdef SIGINT
- signal(SIGINT, handler);
- sigaddset(&mask, SIGINT);
-#endif
-
- sigprocmask(SIG_UNBLOCK, &mask, 0);
-#endif //Q_OS_UNIX
-
-}
diff --git a/src/shared/akcrash.h b/src/shared/akcrash.h
deleted file mode 100644
index 57e4f2a..0000000
--- a/src/shared/akcrash.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * This file is part of the KDE Libraries
- * Copyright (C) 2000 Timo Hummel <timo.hummel@sap.com>
- * Tom Braun <braunt@fh-konstanz.de>
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef AKCRASH_H
-#define AKCRASH_H
-
-#include <QString>
-
-QString akBacktrace();
-
-class AkonadiCrash
-{
-public:
- typedef void (*HandlerType)(int);
-
- static void init();
- static void setEmergencyMethod(HandlerType method);
- static void setShutdownMethod(HandlerType method);
-};
-
-#endif
diff --git a/src/shared/akdebug.cpp b/src/shared/akdebug.cpp
index 79e9ec6..1002164 100644
--- a/src/shared/akdebug.cpp
+++ b/src/shared/akdebug.cpp
@@ -22,7 +22,6 @@
*/
#include "akdebug.h"
-#include "akcrash.h"
#include <private/standarddirs_p.h>
@@ -32,6 +31,8 @@
#include <QMutex>
#include <QLoggingCategory>
+#include <KCrash/KCrash>
+
#include <cassert>
class FileDebugStream : public QIODevice
@@ -184,7 +185,7 @@ void akCategoryFilter(QLoggingCategory *category)
void akInit(const QString &appName)
{
- AkonadiCrash::init();
+ KCrash::initialize();
sInstance()->setName(appName);
QFileInfo infoOld(sInstance()->errorLogFileName() + QLatin1String(".old"));