#include #include #include #include #include #include #include #include #include #include "LeahiRtController.h" #define log qDebug().noquote() int main(int argc, char *argv[]) { // Block SIGINT and SIGTERM from normal delivery; redirect them to a fd. sigset_t mask; sigemptyset(&mask); sigaddset(&mask, SIGINT); sigaddset(&mask, SIGTERM); sigprocmask(SIG_BLOCK, &mask, nullptr); const int sfd = signalfd(-1, &mask, SFD_CLOEXEC); if (sfd == -1) { qCritical("Failed to create signalfd"); return 1; } QCoreApplication app(argc, argv); app.setApplicationName("LeahiRt"); app.setApplicationVersion("1.0"); // Notifier runs on the main thread inside the event loop — safe to call quit(). QSocketNotifier notifier(sfd, QSocketNotifier::Read); QObject::connect(¬ifier, &QSocketNotifier::activated, [&](int fd) { struct signalfd_siginfo info{}; (void)read(fd, &info, sizeof(info)); if (info.ssi_signo == SIGINT) { log << "Application terminated by SIGINT"; } else if (info.ssi_signo == SIGTERM) { log << "Application terminated by SIGTERM"; } app.quit(); }); QCommandLineParser parser; parser.setApplicationDescription("Leahi Real-time Cloud Data Transmission daemon."); parser.addHelpOption(); parser.addVersionOption(); QCommandLineOption configOption( {"c", "config"}, "Path to the configuration INI file.", "config", QDir(app.applicationDirPath()).filePath("config/LeahiRt.ini") ); QCommandLineOption msgHandlingOption( {"m", "msg_handling"}, "Path to the message handling INI file.", "msg_handling", QDir(app.applicationDirPath()).filePath("config/LeahiRtMsgHandling.ini") ); parser.addOption(configOption); parser.addOption(msgHandlingOption); parser.process(app); LeahiRtController rtController(parser.value(configOption), parser.value(msgHandlingOption)); rtController.connectToAgent(); return app.exec(); }