made Commadnlineoptions into a class
Some checks failed
Build on RHEL9 / build (push) Failing after 12s
Build on RHEL8 / build (push) Failing after 18s

This commit is contained in:
2025-07-07 14:52:01 +02:00
parent d18ea00b85
commit 9a37cee4e9
5 changed files with 286 additions and 202 deletions

View File

@ -9,263 +9,302 @@
#include <csignal> #include <csignal>
#include <cstring> #include <cstring>
#include <getopt.h>
#include <unistd.h> #include <unistd.h>
#define MAX_RECEIVERS 1024 ParsedOptions CommandLineOptions::parse(int argc, char *argv[]) {
ParsedOptions parseCommandLine(AppType app, int argc, char* argv[]) {
CommonOptions base; CommonOptions base;
base.port = DEFAULT_TCP_RX_PORTNO; base.port = DEFAULT_TCP_RX_PORTNO;
MultiReceiverOptions multi; MultiReceiverOptions multi;
FrameSyncOptions frame; FrameSyncOptions frame;
uint16_t numReceivers = 1; uint16_t numReceivers = 1;
bool optionalArg = false; bool optionalArg = false;
auto optString = buildOptString();
auto longOptions = buildOptionList();
int opt; int opt;
int option_index = 0; int option_index = 0;
static struct option common_opts[] = { while ((opt = getopt_long(argc, argv, optString.c_str(), longOptions.data(),
{"version", no_argument, nullptr, 'v'}, &option_index)) != -1) {
{"port", required_argument, nullptr, 'p'},
{"uid", required_argument, nullptr, 'u'},
{"help", no_argument, nullptr, 'h'},
{nullptr, 0, nullptr, 0}
};
static struct option single_opts[] = {
{"rx_tcpport", required_argument, nullptr, 't'},
{nullptr, 0, nullptr, 0}
};
static struct option multi_opts[] = {
{"callback", no_argument, nullptr, 'c'},
{"rx_tcpport", required_argument, nullptr, 't'},
{"num-receivers", required_argument, nullptr, 'n'},
{nullptr, 0, nullptr, 0}
};
static struct option frame_sync_opts[] = {
{"print-headers", no_argument, nullptr, 'c'},
{"num-receivers", required_argument, nullptr, 'n'},
{nullptr, 0, nullptr, 0}
};
std::vector<option> options;
options.insert(options.end(), std::begin(common_opts), std::end(common_opts) - 1);
if (app == AppType::SingleReceiver) {
options.insert(options.end(), std::begin(single_opts), std::end(single_opts) - 1);
} else if (app == AppType::MultiReceiver) {
options.insert(options.end(), std::begin(multi_opts), std::end(multi_opts) - 1);
} else if (app == AppType::FrameSynchronizer) {
options.insert(options.end(), std::begin(frame_sync_opts), std::end(frame_sync_opts) - 1);
}
std::string optstring = "vp:u:h";
if (app == AppType::SingleReceiver) {
optstring += "t:";
} else if (app == AppType::MultiReceiver) {
optstring += "cn:t:";
} else if (app == AppType::FrameSynchronizer) {
optstring += "cn:";
}
while ((opt = getopt_long(argc, argv, optstring.c_str(), options.data(), &option_index)) != -1) {
switch (opt) { switch (opt) {
case 'v': case 'v':
base.versionRequested = true; case 'h':
std::cout << getVersion(app) << std::endl; case 'p':
break; case 'u':
handleCommonOption(opt, optarg, base);
break;
case 'h': case 'c':
base.helpRequested = true; case 'n':
std::cout << getHelpMessage(app) << std::endl; case 't':
break; handleAppSpecificOption(opt, optarg, base, multi, frame);
break;
case 't': default:
LOG(sls::logWARNING) << "Deprecated option. Please use 'p' or '--port'."; throw sls::RuntimeError("Invalid arguments." + getHelpMessage());
[[fallthrough]];
case 'p':
try {
base.port = sls::StringTo<uint16_t>(optarg);
} catch (...) {
throw sls::RuntimeError("Invalid port number parsed.");
}
break;
case 'u':
try {
base.userid = sls::StringTo<uint32_t>(optarg);
if (base.userid != static_cast<uid_t>(-1)) {
setEffectiveUID(base.userid);
}
} catch (...) {
throw sls::RuntimeError("Invalid uid parsed.");
}
break;
case 'n':
try {
if (app == AppType::MultiReceiver)
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) {
throw sls::RuntimeError("Invalid number of receivers. Max: " + std::to_string(MAX_RECEIVERS));
}
multi.numReceivers = numReceivers;
frame.numReceivers = numReceivers;
} catch (...) {
throw sls::RuntimeError("Invalid number of receivers parsed." + std::to_string(numReceivers));
}
break;
case 'c':
optionalArg = true;
if (app == AppType::MultiReceiver) {
multi.callbackEnabled = true;
} else if (app == AppType::FrameSynchronizer) {
frame.printHeaders = true;
}
break;
default:
throw sls::RuntimeError("Invalid arguments." + getHelpMessage(app));
} }
} }
// remaining arguments // remaining arguments
if (optind < argc) { if (optind < argc) {
// maintain backward compatibility of [start port] [num receivers] [optional arg] ( for multi receiver and frame synchronizer ) // maintain backward compatibility of [start port] [num receivers]
if (app != AppType::SingleReceiver && slsDetectorDefs::OK == GetDeprecatedCommandLineOptions(argc, argv, base.port, numReceivers, optionalArg)) { // [optional arg] ( for multi receiver and frame synchronizer )
if (app == AppType::MultiReceiver) { if (appType_ != AppType::SingleReceiver &&
GetDeprecated(argc, argv, base.port, numReceivers, optionalArg)) {
if (appType_ == AppType::MultiReceiver) {
multi.numReceivers = numReceivers; multi.numReceivers = numReceivers;
multi.callbackEnabled = optionalArg; multi.callbackEnabled = optionalArg;
} else if (app == AppType::FrameSynchronizer) { } else if (appType_ == AppType::FrameSynchronizer) {
frame.numReceivers = numReceivers; frame.numReceivers = numReceivers;
frame.printHeaders = optionalArg; frame.printHeaders = optionalArg;
} }
} else { } else {
throw sls::RuntimeError("Invalid arguments." + getHelpMessage(app)); throw sls::RuntimeError("Invalid arguments." + getHelpMessage());
} }
} }
LOG(sls::logINFO) << "Number of receivers: " << numReceivers; LOG(sls::logINFO) << "Number of receivers: " << numReceivers;
LOG(sls::logINFO) << "TCP Port: " << base.port; LOG(sls::logINFO) << "TCP Port: " << base.port;
switch (app) { switch (appType_) {
case AppType::SingleReceiver: case AppType::SingleReceiver:
return base; return base;
case AppType::MultiReceiver: case AppType::MultiReceiver:
LOG(sls::logINFO) << "Call back enable: " << multi.callbackEnabled; LOG(sls::logINFO) << "Call back enable: " << multi.callbackEnabled;
static_cast<CommonOptions&>(multi) = base; static_cast<CommonOptions &>(multi) = base;
return multi; return multi;
case AppType::FrameSynchronizer: case AppType::FrameSynchronizer:
LOG(sls::logINFO) << "Print headers: " << frame.printHeaders; LOG(sls::logINFO) << "Print headers: " << frame.printHeaders;
static_cast<CommonOptions&>(frame) = base; static_cast<CommonOptions &>(frame) = base;
return frame; return frame;
} }
throw std::logic_error("Unknown AppType"); throw std::logic_error("Unknown AppType");
} }
std::vector<option> CommandLineOptions::buildOptionList() const {
std::vector<option> opts = {
{"version", no_argument, nullptr, 'v'},
{"port", required_argument, nullptr, 'p'},
{"uid", required_argument, nullptr, 'u'},
{"help", no_argument, nullptr, 'h'},
};
int GetDeprecatedCommandLineOptions(int argc, char *argv[], uint16_t &startPort, uint16_t &numReceivers, bool &optionalArg) { switch (appType_) {
case AppType::SingleReceiver:
opts.push_back({"rx_tcpport", required_argument, nullptr, 't'});
break;
case AppType::MultiReceiver:
opts.push_back({"callback", no_argument, nullptr, 'c'});
opts.push_back({"rx_tcpport", required_argument, nullptr, 't'});
opts.push_back({"num-receivers", required_argument, nullptr, 'n'});
break;
case AppType::FrameSynchronizer:
opts.push_back({"num-receivers", required_argument, nullptr, 'n'});
opts.push_back({"print-headers", no_argument, nullptr, 'c'});
break;
}
opts.push_back({nullptr, 0, nullptr, 0}); // null-terminator for getopt
return opts;
}
std::string CommandLineOptions::buildOptString() const {
std::string optstr = "vp:u:h";
if (appType_ == AppType::MultiReceiver ||
appType_ == AppType::FrameSynchronizer)
optstr += "cn:";
if (appType_ == AppType::SingleReceiver)
optstr += "t:";
return optstr;
}
void CommandLineOptions::handleCommonOption(int opt, const char *optarg,
CommonOptions &base) {
switch (opt) {
case 'v':
base.versionRequested = true;
std::cout << getVersion() << std::endl;
break;
case 'h':
base.helpRequested = true;
std::cout << getHelpMessage() << std::endl;
break;
case 'p':
try {
base.port = sls::StringTo<uint16_t>(optarg);
} catch (...) {
throw sls::RuntimeError("Invalid port number parsed.");
}
break;
case 'u':
try {
base.userid = sls::StringTo<uid_t>(optarg);
if (base.userid != static_cast<uid_t>(-1)) {
setEffectiveUID(base.userid);
}
} catch (...) {
throw sls::RuntimeError("Invalid uid parsed.");
}
break;
}
}
void CommandLineOptions::handleAppSpecificOption(int opt, const char *optarg,
CommonOptions &base,
MultiReceiverOptions &multi,
FrameSyncOptions &frame) {
switch (opt) {
case 'c':
if (appType_ == AppType::MultiReceiver)
multi.callbackEnabled = true;
else if (appType_ == AppType::FrameSynchronizer)
frame.printHeaders = true;
break;
case 'n': {
uint16_t val = 1;
try {
val = sls::StringTo<uint16_t>(optarg);
} catch (...) {
throw sls::RuntimeError("Invalid number of receivers parsed." +
std::to_string(val));
}
if (val == 0 || val > MAX_RECEIVERS) {
throw sls::RuntimeError(
"Invalid number of receivers. Options: 1 - " +
std::to_string(MAX_RECEIVERS));
}
if (appType_ == AppType::MultiReceiver)
multi.numReceivers = val;
else if (appType_ == AppType::FrameSynchronizer)
frame.numReceivers = val;
break;
}
case 't':
LOG(sls::logWARNING) << "Deprecated option 't' and '--rx_tcport'. Use "
"'p' or '--port' instead.";
try {
base.port = sls::StringTo<uint16_t>(optarg);
} catch (...) {
throw sls::RuntimeError("Invalid port number parsed.");
}
break;
}
}
int CommandLineOptions::GetDeprecated(int argc, char *argv[],
uint16_t &startPort,
uint16_t &numReceivers,
bool &optionalArg) {
std::string deprecatedMessage = std::string deprecatedMessage =
"Detected deprecated Options. Please update.\n"; "Detected deprecated Options. Please update.\n";
if (argc > 1) { if (argc > 1) {
try { try {
if (argc == 3 || argc == 4) { if (argc == 3 || argc == 4) {
startPort = sls::StringTo<uint16_t>(argv[1]); try {
numReceivers = sls::StringTo<uint16_t>(argv[2]); startPort = sls::StringTo<uint16_t>(argv[1]);
numReceivers = sls::StringTo<uint16_t>(argv[2]);
} catch (...) {
throw sls::RuntimeError(
"Invalid port number or number of receivers parsed.");
}
if (numReceivers > MAX_RECEIVERS) { if (numReceivers > MAX_RECEIVERS) {
LOG(sls::logWARNING) << deprecatedMessage;
LOG(sls::logERROR) LOG(sls::logERROR)
<< "Did you mix up the order of the arguments? Max " << "Did you mix up the order of the arguments? Max "
"number of recievers: " << MAX_RECEIVERS; "number of recievers: " << MAX_RECEIVERS;
return slsDetectorDefs::FAIL; return 0;
} }
if (numReceivers == 0) { if (numReceivers == 0) {
LOG(sls::logWARNING) << deprecatedMessage; LOG(sls::logERROR)
LOG(sls::logERROR) << "Invalid number of receivers. Options: 1 - " << MAX_RECEIVERS; << "Invalid number of receivers. Options:1 - "
<< MAX_RECEIVERS;
return slsDetectorDefs::FAIL; return slsDetectorDefs::FAIL;
} }
if (argc == 4) { if (argc == 4) {
optionalArg = sls::StringTo<bool>(argv[3]); try {
optionalArg = sls::StringTo<bool>(argv[3]);
} catch (...) {
throw sls::RuntimeError("Invalid optional argument "
"parsed. Expected 1 (true) or "
"0 (false).");
}
} }
} else } else
throw std::runtime_error("Invalid number of arguments"); throw std::runtime_error("Invalid number of arguments");
} catch (const std::exception &e) { } catch (const std::exception &e) {
LOG(sls::logWARNING) << deprecatedMessage; LOG(sls::logWARNING) << deprecatedMessage;
LOG(sls::logERROR) << e.what(); LOG(sls::logERROR) << e.what();
return slsDetectorDefs::FAIL; return 0;
} }
} }
return slsDetectorDefs::OK; return 1;
} }
void setEffectiveUID(uid_t uid) { std::string CommandLineOptions::getTypeString() {
if (geteuid() == uid) { switch (appType_) {
LOG(sls::logINFO) case AppType::SingleReceiver:
<< "Process already has the same Effective UID " << uid; return "SingleReceiver";
} else { case AppType::MultiReceiver:
if (seteuid(uid) != 0 || geteuid() != uid) { return "MultiReceiver";
throw sls::RuntimeError("Could not set Effective UID"); case AppType::FrameSynchronizer:
} return "FrameSynchronizer";
LOG(sls::logINFO) << "Process Effective UID changed to " << uid; default:
return "Unknown";
} }
} }
std::string getTypeString(const AppType app) { std::string CommandLineOptions::getVersion() {
switch (app) { return getTypeString() + " Version: " + APIRECEIVER;
case AppType::SingleReceiver: return "SingleReceiver";
case AppType::MultiReceiver: return "MultiReceiver";
case AppType::FrameSynchronizer: return "FrameSynchronizer";
default: return "Unknown";
}
} }
std::string getVersion(AppType app) { std::string CommandLineOptions::getHelpMessage() {
return getTypeString(app) + " Version: " + APIRECEIVER; switch (appType_) {
} case AppType::SingleReceiver:
return std::string("\nUsage: ") + getTypeString() + " Options:\n" +
"\t-v, --version : Version.\n" +
"\t-p, --port : TCP port to communicate with client "
"for "
"configuration. Non-zero and 16 bit.\n" +
"\t-u, --uid : Set effective user id if receiver "
"started "
"with privileges. \n\n";
std::string getHelpMessage(AppType app) { case AppType::MultiReceiver:
switch (app) { return std::string("\nUsage: " + getTypeString() + " Options:\n") +
case AppType::SingleReceiver: "\t-v, --version : Version.\n" +
return std::string("\nUsage: ") + getTypeString(app) + " Options:\n" + "\t-n, --num-receivers : Number of receivers.\n" +
"\t-v, --version : Version.\n" + "\t-p, --port : TCP port to communicate with client "
"\t-p, --port : TCP port to communicate with client for " "for "
"configuration. Non-zero and 16 bit.\n" + "configuration. Non-zero and 16 bit.\n" +
"\t-u, --uid : Set effective user id if receiver started " "\t-c, --callback : Enable dummy callbacks for debugging. "
"with privileges. \n\n"; "Disabled by default. \n" +
"\t-u, --uid : Set effective user id if receiver "
"started "
"with privileges. \n\n";
case AppType::MultiReceiver: case AppType::FrameSynchronizer:
return std::string("\nUsage: " + getTypeString(app) + " Options:\n") + return std::string("\nUsage: " + getTypeString() + " Options:\n") +
"\t-v, --version : Version.\n" + "\t-v, --version : Version.\n" +
"\t-n, --num-receivers : Number of receivers.\n" + "\t-n, --num-receivers : Number of receivers.\n" +
"\t-p, --port : TCP port to communicate with client for " "\t-p, --port : TCP port to communicate with client "
"configuration. Non-zero and 16 bit.\n" + "for "
"\t-c, --callback : Enable dummy callbacks for debugging. " "configuration. Non-zero and 16 bit.\n" +
"Disabled by default. \n" + "\t-c, --print-headers : Print callback headers for debugging. "
"\t-u, --uid : Set effective user id if receiver started " "Disabled by default.\n" +
"with privileges. \n\n"; "\t-u, --uid : Set effective user id if receiver "
"started "
case AppType::FrameSynchronizer: "with privileges. \n\n";
return std::string("\nUsage: " + getTypeString(app) + " Options:\n") +
"\t-v, --version : Version.\n" +
"\t-n, --num-receivers : Number of receivers.\n" +
"\t-p, --port : TCP port to communicate with client for "
"configuration. Non-zero and 16 bit.\n" +
"\t-c, --print-headers : Print callback headers for debugging. "
"Disabled by default.\n" +
"\t-u, --uid : Set effective user id if receiver started "
"with privileges. \n\n";
} }
throw sls::RuntimeError("Unknown AppType for help message"); throw sls::RuntimeError("Unknown AppType for help message");
} }
void setupSignalHandler(int signal, void (*handler)(int)) { void CommandLineOptions::setupSignalHandler(int signal, void (*handler)(int)) {
// Catch signal SIGINT to close files and call destructors properly // Catch signal SIGINT to close files and call destructors properly
struct sigaction sa{}; struct sigaction sa{};
sa.sa_handler = handler; sa.sa_handler = handler;
@ -275,3 +314,15 @@ void setupSignalHandler(int signal, void (*handler)(int)) {
LOG(sls::logERROR) << "Could not set handler for " << strsignal(signal); LOG(sls::logERROR) << "Could not set handler for " << strsignal(signal);
} }
} }
void CommandLineOptions::setEffectiveUID(uid_t uid) {
if (geteuid() == uid) {
LOG(sls::logINFO) << "Process already has the same Effective UID "
<< uid;
} else {
if (seteuid(uid) != 0 || geteuid() != uid) {
throw sls::RuntimeError("Could not set Effective UID");
}
LOG(sls::logINFO) << "Process Effective UID changed to " << uid;
}
}

View File

@ -3,8 +3,10 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
#include <getopt.h>
#include <string> #include <string>
#include <variant> #include <variant>
#include <vector>
enum class AppType { enum class AppType {
MultiReceiver, MultiReceiver,
@ -32,10 +34,29 @@ struct FrameSyncOptions : CommonOptions {
using ParsedOptions = std::variant<CommonOptions, MultiReceiverOptions, FrameSyncOptions>; using ParsedOptions = std::variant<CommonOptions, MultiReceiverOptions, FrameSyncOptions>;
ParsedOptions parseCommandLine(AppType app, int argc, char* argv[]); class CommandLineOptions {
int GetDeprecatedCommandLineOptions(int argc, char *argv[], uint16_t &startPort, uint16_t &numReceivers, bool &optionalArg); public:
void setEffectiveUID(uid_t uid); constexpr explicit CommandLineOptions(AppType app) : appType_(app) {}
std::string getTypeString(const AppType app); ParsedOptions parse(int argc, char *argv[]);
std::string getVersion(AppType app); std::string getTypeString();
std::string getHelpMessage(AppType app); std::string getVersion();
void setupSignalHandler(int signal, void (*handler)(int)); std::string getHelpMessage();
static void setupSignalHandler(int signal, void (*handler)(int));
static void setEffectiveUID(uid_t uid);
private:
AppType appType_;
std::vector<option> buildOptionList() const;
std::string buildOptString() const;
void handleCommonOption(int opt, const char *optarg, CommonOptions &base);
void handleAppSpecificOption(int opt, const char *optarg,
CommonOptions &base,
MultiReceiverOptions &multi,
FrameSyncOptions &frame);
static int GetDeprecated(int argc, char *argv[], uint16_t &startPort,
uint16_t &numReceivers, bool &optionalArg);
static constexpr uint16_t MAX_RECEIVERS = 1000;
};

View File

@ -503,7 +503,8 @@ void sigInterruptHandler(int p) {
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
auto opts = parseCommandLine(AppType::MultiReceiver, argc, argv); CommandLineOptions cli(AppType::SingleReceiver);
auto opts = cli.parse(argc, argv);
auto &o = std::get<CommonOptions>(opts); auto &o = std::get<CommonOptions>(opts);
auto &f = std::get<FrameSyncOptions>(opts); auto &f = std::get<FrameSyncOptions>(opts);
if (o.versionRequested || o.helpRequested) { if (o.versionRequested || o.helpRequested) {
@ -512,8 +513,11 @@ int main(int argc, char *argv[]) {
LOG(sls::logINFOBLUE) << "Current Process [ Tid: " << gettid() << ']'; LOG(sls::logINFOBLUE) << "Current Process [ Tid: " << gettid() << ']';
setupSignalHandler(SIGINT, sigInterruptHandler); // close files on ctrl+c // close files on ctrl+c
setupSignalHandler(SIGPIPE, SIG_IGN); // handle locally on socket crash CommandLineOptions::setupSignalHandler(SIGINT, sigInterruptHandler);
// handle locally on socket crash
CommandLineOptions::setupSignalHandler(SIGPIPE, SIG_IGN);
semaphores.resize(f.numReceivers); semaphores.resize(f.numReceivers);
for (auto &s : semaphores) { for (auto &s : semaphores) {
sem_init(&s, 1, 0); sem_init(&s, 1, 0);

View File

@ -143,7 +143,8 @@ void sigInterruptHandler(int signal) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
auto opts = parseCommandLine(AppType::MultiReceiver, argc, argv); CommandLineOptions cli(AppType::SingleReceiver);
auto opts = cli.parse(argc, argv);
auto& o = std::get<CommonOptions>(opts); auto& o = std::get<CommonOptions>(opts);
auto &m = std::get<MultiReceiverOptions>(opts); auto &m = std::get<MultiReceiverOptions>(opts);
if (o.versionRequested || o.helpRequested) { if (o.versionRequested || o.helpRequested) {
@ -152,8 +153,11 @@ int main(int argc, char *argv[]) {
LOG(sls::logINFOBLUE) << "Current Process [ Tid: " << gettid() << ']'; LOG(sls::logINFOBLUE) << "Current Process [ Tid: " << gettid() << ']';
setupSignalHandler(SIGINT, sigInterruptHandler); // close files on ctrl+c // close files on ctrl+c
setupSignalHandler(SIGPIPE, SIG_IGN); // handle locally on socket crash CommandLineOptions::setupSignalHandler(SIGINT, sigInterruptHandler);
// handle locally on socket crash
CommandLineOptions::setupSignalHandler(SIGPIPE, SIG_IGN);
sem_init(&semaphore, 1, 0); sem_init(&semaphore, 1, 0);
/** - loop over receivers */ /** - loop over receivers */
@ -219,7 +223,7 @@ int main(int argc, char *argv[]) {
/** - Parent process ignores SIGINT and waits for all the child processes to /** - Parent process ignores SIGINT and waits for all the child processes to
* handle the signal */ * handle the signal */
setupSignalHandler(SIGINT, SIG_IGN); CommandLineOptions::setupSignalHandler(SIGINT, SIG_IGN);
/** - Print Ready and Instructions how to exit */ /** - Print Ready and Instructions how to exit */
std::cout << "Ready ... \n"; std::cout << "Ready ... \n";

View File

@ -31,7 +31,8 @@ void sigInterruptHandler(int signal) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
auto opts = parseCommandLine(AppType::SingleReceiver, argc, argv); CommandLineOptions cli(AppType::SingleReceiver);
auto opts = cli.parse(argc, argv);
auto& o = std::get<CommonOptions>(opts); auto& o = std::get<CommonOptions>(opts);
if (o.versionRequested || o.helpRequested) { if (o.versionRequested || o.helpRequested) {
return EXIT_SUCCESS; return EXIT_SUCCESS;
@ -39,8 +40,11 @@ int main(int argc, char *argv[]) {
LOG(sls::logINFOBLUE) << "Current Process [ Tid: " << gettid() << " ]"; LOG(sls::logINFOBLUE) << "Current Process [ Tid: " << gettid() << " ]";
setupSignalHandler(SIGINT, sigInterruptHandler); // close files on ctrl+c // close files on ctrl+c
setupSignalHandler(SIGPIPE, SIG_IGN); // handle locally on socket crash CommandLineOptions::setupSignalHandler(SIGINT, sigInterruptHandler);
// handle locally on socket crash
CommandLineOptions::setupSignalHandler(SIGPIPE, SIG_IGN);
sem_init(&semaphore, 1, 0); sem_init(&semaphore, 1, 0);
try { try {