diff --git a/src/service/Application.cpp b/src/service/Application.cpp --- a/src/service/Application.cpp +++ b/src/service/Application.cpp @@ -46,7 +46,6 @@ #include // System -#include #include #include #include @@ -140,9 +139,9 @@ void Application::init() { - if (!KDBusConnectionPool::threadConnection().registerService( - KAMD_DBUS_SERVICE)) { - exit(EXIT_SUCCESS); + if (!KDBusConnectionPool::threadConnection().registerService(KAMD_DBUS_SERVICE)) { + QCoreApplication::exit(EXIT_SUCCESS); + return; } // KAMD is a daemon, if it crashes it is not a problem as @@ -325,7 +324,7 @@ const auto arguments = application.arguments(); if (arguments.size() == 0) { - exit(EXIT_FAILURE); + QCoreApplication::exit(EXIT_FAILURE); } else if (arguments.size() != 1 && (arguments.size() != 2 || arguments[1] == "--help")) { @@ -336,54 +335,52 @@ << "start-daemon\tStarts the service without forking (use with caution)\n" << "--help\tThis help message\n"; - exit(EXIT_SUCCESS); + QCoreApplication::exit(EXIT_SUCCESS); } else if (arguments.size() == 1 || arguments[1] == "start") { // Checking whether the service is already running if (isServiceRunning()) { QTextStream(stdout) << "Already running\n"; - exit(EXIT_SUCCESS); - } - - // Creating the watcher, but not on the wall + QCoreApplication::exit(EXIT_SUCCESS); + } else { - QDBusServiceWatcher watcher(QStringLiteral("org.kde.ActivityManager"), - QDBusConnection::sessionBus()); + // Creating the watcher, but not on the wall - QObject::connect(&watcher, &QDBusServiceWatcher::serviceRegistered, - [] (const QString &service) { - if (service != KAMD_DBUS_SERVICE) { - return; - } + QDBusServiceWatcher watcher(QStringLiteral("org.kde.ActivityManager"), + QDBusConnection::sessionBus()); - QTextStream(stdout) - << "Service started, version: " << runningServiceVersion() - << "\n"; + QObject::connect(&watcher, &QDBusServiceWatcher::serviceRegistered, + [] (const QString &service) { + if (service != KAMD_DBUS_SERVICE) { + return; + } - exit(EXIT_SUCCESS); - }); + QTextStream(stdout) + << "Service started, version: " << runningServiceVersion() + << "\n"; - // Starting the dameon + QCoreApplication::exit(EXIT_SUCCESS); + }); - QProcess::startDetached( - KAMD_INSTALL_PREFIX "/bin/kactivitymanagerd", - QStringList{"start-daemon"} - ); + // Starting the dameon - return application.exec(); + QProcess::startDetached( + KAMD_INSTALL_PREFIX "/bin/kactivitymanagerd", + QStringList{"start-daemon"} + ); + } } else if (arguments[1] == "stop") { if (!isServiceRunning()) { QTextStream(stdout) << "Service not running\n"; - exit(EXIT_SUCCESS); - } - - callOnRunningService("quit"); + } else { + callOnRunningService("quit"); - QTextStream(stdout) << "Service stopped\n"; + QTextStream(stdout) << "Service stopped\n"; + } - return EXIT_SUCCESS; + QCoreApplication::exit(EXIT_SUCCESS); } else if (arguments[1] == "status") { @@ -396,7 +393,7 @@ } - return EXIT_SUCCESS; + QCoreApplication::exit(EXIT_SUCCESS); } else if (arguments[1] == "start-daemon") { // Really starting the activity manager @@ -413,33 +410,14 @@ #endif application.init(); - + // Keep the KDBusService alive return application.exec(); } else { QTextStream(stdout) << "Unrecognized command: " << arguments[1] << '\n'; - return EXIT_FAILURE; + QCoreApplication::exit(EXIT_FAILURE); } -} -#ifndef DISABLE_CSIGNAL_HANDLING - -#include - -struct CleanUpOnExit{ - - CleanUpOnExit() { - signal(SIGINT, &CleanUpOnExit::exit); - signal(SIGTERM, &CleanUpOnExit::exit); - } - - static void exit(int sig) { - Q_UNUSED(sig) - - QCoreApplication::exit(0); - } - -} cleanup; - -#endif + return application.exec(); +}