mirror of https://github.com/nymea/nymea.git
74 lines
2.8 KiB
C++
74 lines
2.8 KiB
C++
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
* *
|
|
* Copyright (C) 2016 Simon Stuerz <simon.stuerz@guh.guru> *
|
|
* *
|
|
* This file is part of guh. *
|
|
* *
|
|
* Guh is free software: you can redistribute it and/or modify *
|
|
* it under the terms of the GNU General Public License as published by *
|
|
* the Free Software Foundation, version 2 of the License. *
|
|
* *
|
|
* Guh 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 General Public License for more details. *
|
|
* *
|
|
* You should have received a copy of the GNU General Public License *
|
|
* along with guh. If not, see <http://www.gnu.org/licenses/>. *
|
|
* *
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
#include "guhapplication.h"
|
|
#include "loggingcategories.h"
|
|
#include "guhcore.h"
|
|
|
|
#include "unistd.h"
|
|
#include "signal.h"
|
|
|
|
namespace guhserver {
|
|
|
|
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:
|
|
qCDebug(dcApplication) << "Cought SIGQUIT quit signal...";
|
|
break;
|
|
case SIGINT:
|
|
qCDebug(dcApplication) << "Cought SIGINT quit signal...";
|
|
break;
|
|
case SIGTERM:
|
|
qCDebug(dcApplication) << "Cought SIGTERM quit signal...";
|
|
break;
|
|
case SIGHUP:
|
|
qCDebug(dcApplication) << "Cought SIGHUP quit signal...";
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
qCDebug(dcApplication) << "=====================================";
|
|
qCDebug(dcApplication) << "Shutting down guh daemon";
|
|
qCDebug(dcApplication) << "=====================================";
|
|
|
|
GuhCore::instance()->destroy();
|
|
GuhApplication::quit();
|
|
};
|
|
|
|
// all these signals will be ignored.
|
|
for (int sig : ignoreSignals)
|
|
signal(sig, SIG_IGN);
|
|
|
|
for (int sig : quitSignals)
|
|
signal(sig, handler);
|
|
}
|
|
|
|
|
|
GuhApplication::GuhApplication(int &argc, char **argv) :
|
|
QCoreApplication(argc, argv)
|
|
{
|
|
catchUnixSignals({SIGQUIT, SIGINT, SIGTERM, SIGHUP});
|
|
}
|
|
|
|
}
|