36#if defined(_XOPEN_SOURCE) && defined(_POSIX_C_SOURCE) && _XOPEN_SOURCE >= 700 \
37 && _POSIX_C_SOURCE >= 200809L
38 #define HAVE_STRSIGNAL
39#elif defined(_GNU_SOURCE)
40 #define HAVE_STRSIGNAL
45bool crash_report =
false;
46std::string crash_report_filename =
"";
48namespace shamsys::details {
58 const char *signame = strsignal(signum);
60 const char *signame =
"UNKNOWN";
84 std::string log_start = fmt::format(
85 "!!! Received signal : {} (code {}) from world rank {}\n",
92 std::string log_end =
"exiting ...";
95 std::ofstream outfile(crash_report_filename);
96 outfile << log_start << std::endl;
97 outfile << report << std::endl;
98 outfile << log_end << std::endl;
100 std::cout << shambase::format(
102 "Crash report written to {}",
104 crash_report_filename)
107 std::string merged_log = log_start + report + log_end;
108 std::cout << merged_log << std::endl;
118 void register_signals() {
120 if (SHAM_CRASH_REPORT_FILE !=
"") {
122 crash_report_filename
128 struct sigaction sa = {};
129 sa.sa_handler = details::signal_callback_handler;
130 sigemptyset(&sa.sa_mask);
132 sa.sa_flags = SA_RESETHAND;
134 std::array catched_signals = {SIGTERM, SIGINT, SIGSEGV, SIGIOT};
135 for (
auto signum : catched_signals) {
136 if (sigaction(signum, &sa, NULL) != 0) {
138 "Failed to register {} signal handler", details::get_signal_name(signum)));
Header file describing a Node Instance.
const char * get_signal_name(int signum)
Name the received signal.
void signal_callback_handler(int signum)
The handler that will be called when a signal is catched.
This header file contains utility functions related to exception handling in the code.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
std::string getenv_str_default(const char *env_var, std::string default_val)
Get the content of the environment variable if it exist, otherwise return the default value.
i32 world_rank()
Gives the rank of the current process in the MPI communicator.
namespace for the system handling
void init_backtrace_utilities(bool enable_colors)
Initialize the backtrace utilities.
std::string crash_report_backtrace()
Generate a backtrace for the crash report.
This file contains the definition for the stacktrace related functionality.
Utilities to generate a backtrace for the crash report.
This file contains tty info getters.