Skip to content

Commit

Permalink
React to some common Unix signals.
Browse files Browse the repository at this point in the history
  • Loading branch information
brookiestein committed Jul 23, 2024
1 parent 572848d commit 519330f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.28)

project(BtScreenLocker
VERSION 1.6.4
VERSION 1.6.5
LANGUAGES CXX
DESCRIPTION "Daemon to lock your screen if trusted Bluetooth devices go away."
)
Expand Down
20 changes: 19 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <csignal>
#include <map>

#include <QApplication>
Expand All @@ -11,16 +12,18 @@
#include <QSharedPointer>
#include <QStandardPaths>
#include <QTranslator>
#include <QVector>

#include "listener.hpp"
#include "logger.hpp"
#include "screenlocker.hpp"

void setupSignals(const QVector<int> sigs);
void signalHandler(int signal);
QList<QCommandLineOption> commandLineOptions(const char *name);
QTranslator *setAppLanguage(std::map<QString, Logger::TYPE> &logMessages, const QString &language);
int enableAutostart(const QCommandLineParser &parser, Logger &logger, const char *name);
void registerDBusService(Listener &listener, Logger &logger);
void usage(const char *programName);

int main(int argc, char *argv[])
{
Expand All @@ -29,6 +32,8 @@ int main(int argc, char *argv[])
QApplication a(argc, argv);
a.setQuitOnLastWindowClosed(false);

setupSignals({ SIGINT, SIGHUP, SIGTERM, SIGQUIT });

QCommandLineParser parser;
parser.setApplicationDescription(PROJECT_DESCRIPTION);
parser.addHelpOption();
Expand Down Expand Up @@ -111,6 +116,19 @@ int main(int argc, char *argv[])
return a.exec();
}

void setupSignals(const QVector<int> sigs)
{
for (const int sig : sigs) {
signal(sig, signalHandler);
}
}

void signalHandler(int signal)
{
qInfo() << "Exiting because of signal:" << signal;
QApplication::exit(signal);
}

QList<QCommandLineOption> commandLineOptions(const char *name)
{
QList<QCommandLineOption> options;
Expand Down

0 comments on commit 519330f

Please sign in to comment.