Class SigtermGuard
Defined in File SigtermGuard.hpp
Class Documentation
-
class SigtermGuard
RAII guard installing (and later restoring) a SIGTERM handler.
Resets sigtermReceived and installs signalHandler for SIGTERM on construction, restoring whatever disposition was previously in place on destruction – covering every one of run()’s own exit paths (normal return, a caught SIGTERM, or an exception propagating out) uniformly, since none of them can skip a local variable’s own destructor running. Without the restore, a single process that calls SimCluster::run()/SimGalaxy::run() more than once (e.g. a Python session driving several slug runs in a row via run_sim()) would leave slug’s own handler permanently installed process-wide even after the run it was actually meant for has finished, silently overriding whatever the embedding application itself wanted SIGTERM to do afterward. Resetting sigtermReceived here (not just once, at namespace-scope initialization) matters for the same reason: without it, a second run() call in that same process would immediately see the first run’s own already-set flag and exit early on its very first checkpoint, having never actually received a SIGTERM of its own at all.
Shared by SimCluster::run() and SimGalaxy::run(), which are otherwise independent, never-both-running-at-once drivers, each with its own run()/runTrial() to guard – installErrorMessage lets each pass its own std::runtime_error message identifying which one failed to install its handler.
Public Functions
-
inline explicit SigtermGuard(const std::string &installErrorMessage)
Install the SIGTERM handler.
- Parameters:
installErrorMessage –
Message std::runtime_error is constructed with if installation fails; conventionally names the caller (e.g. “SimCluster::run: unable to install
a SIGTERM handler”)
-
inline ~SigtermGuard()
Restore whatever SIGTERM disposition was in place before construction.
-
SigtermGuard(const SigtermGuard&) = delete
-
auto operator=(const SigtermGuard&) -> SigtermGuard& = delete
-
SigtermGuard(SigtermGuard&&) = delete
-
auto operator=(SigtermGuard&&) -> SigtermGuard& = delete
-
inline explicit SigtermGuard(const std::string &installErrorMessage)