Skip to content
Snippets Groups Projects
Commit 3c0b9ccf authored by Jan de Cuveland's avatar Jan de Cuveland Committed by Pierre-Alain Loizeau
Browse files

Fix histserv signal handling

parent 16bc84c5
No related branches found
No related tags found
1 merge request!1820Fix histserv signal handling
......@@ -42,7 +42,9 @@ using cbm::services::histserv::Application;
// ---------------------------------------------------------------------------------------------------------------------
//
Application::Application(ProgramOptions const& opt) : fOpt(opt)
Application::Application(ProgramOptions const& opt, volatile sig_atomic_t* signalStatus)
: fOpt(opt)
, fSignalStatus(signalStatus)
{
/// Read options from executable
LOG(info) << "Options for Application:";
......@@ -84,12 +86,6 @@ Application::Application(ProgramOptions const& opt) : fOpt(opt)
fServer->Restrict("/Stop_Server", "allow=admin");
}
// Provide signal handling for external interruptions
// NOTE: SZh 02.04.2024:
// This function is needed for ZMQ to throw an exception (zmq::error_t) on the interrupt signal. It seems, that
// the actual body of the function does not matter. This behaviour is not understood.
signal(SIGINT, [](int) {});
LOG(info) << "JSROOT location: " << jsrootsys;
}
......@@ -100,7 +96,7 @@ void Application::Exec()
fStopThread = false;
fThread = std::thread(&Application::UpdateHttpServer, this);
LOG(info) << "Listening to ZMQ messages ...";
while (!(fUiCmdActor->GetServerStop())) { //
while (!(fUiCmdActor->GetServerStop()) && *fSignalStatus == 0) {
try {
/// Infinite loop, this is a service which should survive until told otherwise after all
/// FIXME: Start listening to <SOMETHING?!?> to receive histograms and configuration
......@@ -111,27 +107,23 @@ void Application::Exec()
if (!ret) continue;
std::lock_guard<std::mutex> lk(mtx);
if (*ret > 3) { //
if (*ret > 3) {
ReceiveConfigAndData(vMsg);
}
else if (*ret == 1) { //
else if (*ret == 1) {
ReceiveData(vMsg[0]);
}
else { //
else {
LOG(error) << "Invalid number of message parts received: should be either 1 or more than 3 vs " << *ret;
}
}
catch (const zmq::error_t& err) {
if (err.num() == EINTR) {
// FIXME: SZh: Are the socket and the context finished properly?
LOG(info) << "Histogram server execution was interrupted by user. Finishing application";
break;
}
else {
throw err;
if (err.num() != EINTR) {
throw;
}
}
}
// FIXME: SZh: Are the socket and the context finished properly?
}
// ---------------------------------------------------------------------------------------------------------------------
......
......@@ -25,7 +25,7 @@ namespace cbm::services::histserv
public:
/** @brief Standard constructor, initialises the application
** @param opt **/
explicit Application(ProgramOptions const& opt);
explicit Application(ProgramOptions const& opt, volatile sig_atomic_t* signalStatus);
/** @brief Copy constructor forbidden **/
Application(const Application&) = delete;
......@@ -84,6 +84,7 @@ namespace cbm::services::histserv
private:
ProgramOptions const& fOpt; ///< Program options object
volatile sig_atomic_t* fSignalStatus; ///< Global signal status
THttpServer* fServer = nullptr; ///< ROOT Histogram server (JSroot)
std::thread fThread;
bool fStopThread = false;
......
......@@ -5,15 +5,25 @@
#include "Application.h"
#include "ProgramOptions.h"
#include <csignal>
namespace {
volatile sig_atomic_t signal_status = 0;
}
static void signal_handler(int sig) { signal_status = sig; }
using namespace cbm::services::histserv;
int main(int argc, char* argv[])
{
std::signal(SIGINT, signal_handler);
std::signal(SIGTERM, signal_handler);
LOG(info) << "***** Histogram server without FairMQ *****";
try {
ProgramOptions opt(argc, argv);
Application app(opt);
Application app(opt, &signal_status);
app.Exec();
}
catch (std::exception const& e) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment