From bab557f1f59715ce04ec7b4780748a1c971fe6df Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Mon, 22 Jul 2024 08:33:40 +0200 Subject: [PATCH] Add a signal handler for SIGINT when building a detector --- DDCore/src/DetectorImp.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/DDCore/src/DetectorImp.cpp b/DDCore/src/DetectorImp.cpp index 36d8c159a..a39bcdc16 100644 --- a/DDCore/src/DetectorImp.cpp +++ b/DDCore/src/DetectorImp.cpp @@ -33,6 +33,8 @@ #include #include #include +#include +#include // ROOT inlcude files #include @@ -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 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); }