#include #include #include #include #if !defined(__APPLE__) && !defined(_WIN32) /* prctl is Linux only */ #include #endif // getpid() #ifdef _WIN32 #include "console.h" #include #else #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include "HyperionConfig.h" #include #include #include #include #include #include <../../include/db/AuthTable.h> #include "detectProcess.h" #ifdef ENABLE_X11 #include #endif #include "hyperiond.h" #include "systray.h" #include "SuspendHandler.h" using namespace commandline; #define PERM0664 (QFileDevice::ReadOwner | QFileDevice::ReadGroup | QFileDevice::ReadOther | QFileDevice::WriteOwner | QFileDevice::WriteGroup) #ifndef _WIN32 void signal_handler(int signum) { HyperionDaemon* hyperiond = HyperionDaemon::getInstance(); SuspendHandler* suspendHandler = hyperiond->getSuspendHandlerInstance(); if (signum == SIGCHLD) { // only quit when a registered child process is gone // currently this feature is not active ... } else if (signum == SIGUSR1) { if (suspendHandler != nullptr) { suspendHandler->suspend(); } } else if (signum == SIGUSR2) { if (suspendHandler != nullptr) { suspendHandler->resume(); } } } #endif QCoreApplication* createApplication(int &argc, char *argv[]) { bool isGuiApp = false; bool forceNoGui = false; // command line for (int i = 1; i < argc; ++i) { if (qstrcmp(argv[i], "--desktop") == 0) { isGuiApp = true; } else if (qstrcmp(argv[i], "--service") == 0) { isGuiApp = false; forceNoGui = true; } } // on osx/windows gui always available #if defined(__APPLE__) || defined(_WIN32) isGuiApp = true && ! forceNoGui; #else if (!forceNoGui) { isGuiApp = (getenv("DISPLAY") != NULL && (getenv("XDG_SESSION_TYPE") != NULL || getenv("WAYLAND_DISPLAY") != NULL)); } #endif if (isGuiApp) { QApplication* app = new QApplication(argc, argv); // add optional library path app->addLibraryPath(QApplication::applicationDirPath() + "/../lib"); app->setApplicationDisplayName("Hyperion"); #ifndef __APPLE__ app->setWindowIcon(QIcon(":/hyperion-icon-32px.png")); #endif return app; } QCoreApplication* app = new QCoreApplication(argc, argv); app->setApplicationName("Hyperion"); app->setApplicationVersion(HYPERION_VERSION); // add optional library path app->addLibraryPath(QApplication::applicationDirPath() + "/../lib"); return app; } int main(int argc, char** argv) { // initialize main logger and set global log level Logger *log = Logger::getInstance("MAIN"); Logger::setLogLevel(Logger::WARNING); // check if we are running already an instance // TODO Allow one session per user #ifdef _WIN32 const char* processName = "hyperiond.exe"; #else const char* processName = "hyperiond"; #endif // Initialising QCoreApplication QScopedPointer app(createApplication(argc, argv)); bool isGuiApp = !(qobject_cast(app.data()) == nullptr) && QSystemTrayIcon::isSystemTrayAvailable(); DefaultSignalHandler::install(); #ifndef _WIN32 signal(SIGCHLD, signal_handler); signal(SIGUSR1, signal_handler); signal(SIGUSR2, signal_handler); #endif // force the locale setlocale(LC_ALL, "C"); QLocale::setDefault(QLocale::c()); Parser parser("Hyperion Daemon"); parser.addHelpOption(); BooleanOption & versionOption = parser.add (0x0, "version", "Show version information"); Option & userDataOption = parser.add