This repository has been archived on 2026-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
2019-09-13 16:29:07 +02:00

69 lines
2.7 KiB
C++

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2019 Simon Stürz <simon.stuerz@nymea.io> *
* *
* This file is part of nymea-gpio. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 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 *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; If not, see *
* <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "application.h"
#include <QDebug>
#include <signal.h>
static void catchUnixSignals(const std::vector<int>& quitSignals, const std::vector<int>& ignoreSignals = std::vector<int>())
{
auto handler = [](int sig) ->void {
switch (sig) {
case SIGQUIT:
qDebug() << "Cought SIGQUIT quit signal...";
break;
case SIGINT:
qDebug() << "Cought SIGINT quit signal...";
break;
case SIGTERM:
qDebug() << "Cought SIGTERM quit signal...";
break;
case SIGHUP:
qDebug() << "Cought SIGHUP quit signal...";
break;
case SIGSEGV: {
qCritical() << "Cought SIGSEGV signal. Segmentation fault!";
exit(EXIT_FAILURE);
}
default:
break;
}
Application::quit();
};
// all these signals will be ignored.
for (int sig : ignoreSignals)
signal(sig, SIG_IGN);
for (int sig : quitSignals)
signal(sig, handler);
}
Application::Application(int &argc, char **argv) :
QCoreApplication(argc, argv)
{
catchUnixSignals({SIGQUIT, SIGINT, SIGTERM, SIGHUP, SIGSEGV});
}