Commit 8c267ea4 authored by Lisa's avatar Lisa

Deinitialized backend in fault situations

parent 93cbb2fc
......@@ -157,3 +157,9 @@ void OperationManager::quit()
QCoreApplication::instance()->quit();
}
void OperationManager::staticQuit(int sig)
{
Q_UNUSED(sig)
Akabei::Backend::instance()->deInit();
QCoreApplication::instance()->quit();
}
......@@ -23,6 +23,9 @@ Q_OBJECT
public:
explicit OperationManager(APM::OperationType type, QList< APM::OperationName > operations, QHash<APM::OptionName, QStringList> options, QStringList args, QObject* parent = 0);
virtual ~OperationManager();
/* This is just the static version of the quit() slot below, to be passed as a signal handler to sigaction(3) */
static void staticQuit(int);
private slots:
void statusChanged(Akabei::Backend::Status);
......
......@@ -19,6 +19,8 @@
#include <akabeiaboutdata.h>
#include <stdlib.h>
#include <signal.h>
#include <QCoreApplication>
#include <QTextStream>
#include <QHash>
......@@ -356,6 +358,18 @@ void initPakabeiOperations(CommandLineParser *parser)
parser->addOperation(perform);
}
void connectMainSignals()
{
struct sigaction act;
memset(&act, 0, sizeof(struct sigaction));
act.sa_handler = OperationManager::staticQuit;
sigaction(SIGINT, &act, NULL);
sigaction(SIGQUIT, &act, NULL);
sigaction(SIGABRT, &act, NULL);
sigaction(SIGTERM, &act, NULL);
}
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
......@@ -406,6 +420,11 @@ int main(int argc, char **argv)
exit(1);
}
/*
* If we arrived here, akabei is going to initialize the backend soon. Here we make sure it is always
* de-initialized properly even when akabei is terminated with CTRL+C, or because of a segfault.
*/
connectMainSignals();
OperationManager apm(parser->type(), parser->operations(), parser->options(), parser->args());
delete parser;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment