works, need to add tests

This commit is contained in:
2025-07-07 12:20:40 +02:00
parent 4ff29161d4
commit d18ea00b85
6 changed files with 78 additions and 110 deletions

View File

@@ -7,6 +7,11 @@
#include "sls/ToString.h"
#include "sls/logger.h"
#include <csignal>
#include <cstring>
#include <getopt.h>
#include <unistd.h>
#define MAX_RECEIVERS 1024
ParsedOptions parseCommandLine(AppType app, int argc, char* argv[]) {
@@ -108,7 +113,7 @@ ParsedOptions parseCommandLine(AppType app, int argc, char* argv[]) {
multi.numReceivers = sls::StringTo<uint16_t>(optarg);
else if (app == AppType::FrameSynchronizer)
frame.numReceivers = sls::StringTo<uint16_t>(optarg);
if (numReceivers < 0 || numReceivers > MAX_RECEIVERS) {
if (numReceivers == 0 || numReceivers > MAX_RECEIVERS) {
throw sls::RuntimeError("Invalid number of receivers. Max: " + std::to_string(MAX_RECEIVERS));
}
multi.numReceivers = numReceivers;
@@ -257,4 +262,16 @@ std::string getHelpMessage(AppType app) {
"\t-u, --uid : Set effective user id if receiver started "
"with privileges. \n\n";
}
throw sls::RuntimeError("Unknown AppType for help message");
}
void setupSignalHandler(int signal, void (*handler)(int)) {
// Catch signal SIGINT to close files and call destructors properly
struct sigaction sa{};
sa.sa_handler = handler;
sigemptyset(&sa.sa_mask); // dont block additional signals
sa.sa_flags = 0;
if (sigaction(signal, &sa, nullptr) == -1) {
LOG(sls::logERROR) << "Could not set handler for " << strsignal(signal);
}
}