Skip to content

Commit

Permalink
Add a signal handler for SIGINT when building a detector
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcarcell committed Jul 22, 2024
1 parent fe64884 commit bab557f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions DDCore/src/DetectorImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include <stdexcept>
#include <cerrno>
#include <mutex>
#include <csignal>
#include <cstdlib>

// ROOT inlcude files
#include <TGeoSystemOfUnits.h>
Expand Down Expand Up @@ -811,6 +813,19 @@ void DetectorImp::init() {
/// Read any geometry description or alignment file
void DetectorImp::fromXML(const std::string& xmlfile, DetectorBuildType build_type) {
std::lock_guard<std::recursive_mutex> lock(s_detector_apply_lock);

// Install signal handler for SIGINT (Ctrl-C)
struct sigaction sigIntHandler;

sigIntHandler.sa_handler = [](int) {
std::cerr << "Caught signal SIGINT, exiting..." << std::endl;
exit(1);
};
sigemptyset(&sigIntHandler.sa_mask);
sigIntHandler.sa_flags = 0;

sigaction(SIGINT, &sigIntHandler, NULL);

m_buildType = build_type;
processXML(xmlfile, 0);
}
Expand Down

0 comments on commit bab557f

Please sign in to comment.