From 542a5b7636d9502383b687b389c8e6e43a571fa7 Mon Sep 17 00:00:00 2001 From: Matti Viljanen Date: Sun, 26 Apr 2020 11:32:03 +0300 Subject: [PATCH] Exit gracefully on Ctrl-C and service stop --- service/src/harbour-batterybuddy-daemon.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/service/src/harbour-batterybuddy-daemon.cpp b/service/src/harbour-batterybuddy-daemon.cpp index 6703d21..3a31a9f 100644 --- a/service/src/harbour-batterybuddy-daemon.cpp +++ b/service/src/harbour-batterybuddy-daemon.cpp @@ -4,6 +4,7 @@ #include "battery.h" #include "settings.h" #include +#include int main(int argc, char** argv) { @@ -44,6 +45,11 @@ int main(int argc, char** argv) QObject::connect(updater, SIGNAL(timeout()), battery, SLOT(updateData())); updater->start(3000); + // Exit gracefully on Ctrl-C and service stop + QObject::connect(&app, SIGNAL(aboutToQuit()), battery, SLOT(shutdown())); + signal(SIGINT, app.exit); + signal(SIGTERM, app.exit); + int retval = app.exec(); return retval;