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 2d2bf5b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions DDCore/src/DetectorLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

// C/C++ include files
#include <stdexcept>
#include <csignal>
#include <cstdlib>
#include <iostream>

#ifndef __TIXML__
#include <xercesc/dom/DOMException.hpp>
Expand All @@ -47,6 +50,19 @@ DetectorLoad::~DetectorLoad() {

/// Process XML unit and adopt all data from source structure.
void DetectorLoad::processXML(const std::string& xmlfile, xml::UriReader* entity_resolver) {

// 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);

try {
xml::DocumentHolder doc(xml::DocumentHandler().load(xmlfile,entity_resolver));
if ( doc ) {
Expand Down

0 comments on commit 2d2bf5b

Please sign in to comment.