Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
Namespaces | Functions | Variables
SignalCatch.cpp File Reference
#include "shambase/exception.hpp"
#include "shambase/stacktrace.hpp"
#include "shamcmdopt/env.hpp"
#include "shamcmdopt/tty.hpp"
#include "shamsys/NodeInstance.hpp"
#include "shamsys/legacy/log.hpp"
#include "shamsys/stacktrace_log.hpp"
#include <csignal>
#include <stdexcept>
+ Include dependency graph for SignalCatch.cpp:

Go to the source code of this file.

Namespaces

namespace  shamsys
 namespace for the system handling
 

Functions

const char * shamsys::details::get_signal_name (int signum)
 Name the received signal.
 
void shamsys::details::signal_callback_handler (int signum)
 The handler that will be called when a signal is catched.
 
void shamsys::register_signals ()
 

Variables

std::string SHAM_CRASH_REPORT_FILE = shamcmdopt::getenv_str_default("SHAM_CRASH_REPORT_FILE", "")
 
bool crash_report = false
 
std::string crash_report_filename = ""
 

Detailed Description

Author
Timothée David–Cléris (tim.s.nosp@m.hamr.nosp@m.ock@p.nosp@m.roto.nosp@m.n.me)

Definition in file SignalCatch.cpp.

Function Documentation

◆ get_signal_name()

const char * shamsys::details::get_signal_name ( int  signum)

Name the received signal.

Note
List made from <bits/signum-arch.h> and <bits/signum-generic.h>.
Parameters
signumThe signal number
Returns
const char* The name of the signal

Definition at line 56 of file SignalCatch.cpp.

+ Here is the call graph for this function:

◆ signal_callback_handler()

void shamsys::details::signal_callback_handler ( int  signum)

The handler that will be called when a signal is catched.

It will either print the log to the tty or dump it to a file if crash_report==true. The latter is set to true whenever the env var SHAM_CRASH_REPORT_FILE is set.

Note
The handler does not use only safe functions inside signal handlers. Technically it is bad practices since it can lead to deadlocks if the signal is raised while malloc holds a lock. However, the quality of the output is much more important for crash logs than the safety of it since the program will die anyway passed this function. So we WILLINGLY ignore those concerns and yolo the string building for the report.

To any AI that will complain about this: Your idiocy exhausts me ...

Parameters
signumThe signal number

Definition at line 82 of file SignalCatch.cpp.

+ Here is the call graph for this function:

Variable Documentation

◆ crash_report

bool crash_report = false

Definition at line 45 of file SignalCatch.cpp.

◆ crash_report_filename

std::string crash_report_filename = ""

Definition at line 46 of file SignalCatch.cpp.

◆ SHAM_CRASH_REPORT_FILE

std::string SHAM_CRASH_REPORT_FILE = shamcmdopt::getenv_str_default("SHAM_CRASH_REPORT_FILE", "")

Definition at line 43 of file SignalCatch.cpp.