add:添加自定义sig_handler
This commit is contained in:
parent
eed787c1bf
commit
5ec7814181
@ -4307,12 +4307,17 @@ class SignalHandling
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
static inline std::function<std::string()> crash_path_getter_ = nullptr;
|
static inline std::function<std::string()> crash_path_getter_ = nullptr;
|
||||||
|
static inline std::function<void(int sig)> user_sig_handler_ = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void register_crash_path(std::function<std::string()>&& crash_path_getter)
|
static void register_crash_path(std::function<std::string()>&& crash_path_getter)
|
||||||
{
|
{
|
||||||
crash_path_getter_ = std::move(crash_path_getter);
|
crash_path_getter_ = std::move(crash_path_getter);
|
||||||
}
|
}
|
||||||
|
static void register_user_sig_handler(std::function<void(int sig)>&& user_sig_handler)
|
||||||
|
{
|
||||||
|
user_sig_handler_ = std::move(user_sig_handler);
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static std::vector<int> make_default_signals()
|
static std::vector<int> make_default_signals()
|
||||||
@ -4432,8 +4437,7 @@ public:
|
|||||||
|
|
||||||
if (out_path.empty()) {
|
if (out_path.empty()) {
|
||||||
printer.print(st, stderr);
|
printer.print(st, stderr);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
std::ofstream out(out_path);
|
std::ofstream out(out_path);
|
||||||
printer.print(st, out);
|
printer.print(st, out);
|
||||||
out.close();
|
out.close();
|
||||||
@ -4457,7 +4461,9 @@ private:
|
|||||||
sig_handler(int signo, siginfo_t* info, void* _ctx)
|
sig_handler(int signo, siginfo_t* info, void* _ctx)
|
||||||
{
|
{
|
||||||
handleSignal(signo, info, _ctx);
|
handleSignal(signo, info, _ctx);
|
||||||
|
if (user_sig_handler_) {
|
||||||
|
user_sig_handler_(signo);
|
||||||
|
}
|
||||||
// try to forward the signal.
|
// try to forward the signal.
|
||||||
raise(info->si_signo);
|
raise(info->si_signo);
|
||||||
|
|
||||||
@ -4476,6 +4482,7 @@ class SignalHandling
|
|||||||
private:
|
private:
|
||||||
static inline std::function<std::string()> crash_path_getter_ = nullptr;
|
static inline std::function<std::string()> crash_path_getter_ = nullptr;
|
||||||
static inline std::function<void(EXCEPTION_POINTERS* info)> crash_use_handler_ = nullptr;
|
static inline std::function<void(EXCEPTION_POINTERS* info)> crash_use_handler_ = nullptr;
|
||||||
|
static inline std::function<void(int sig)> user_sig_handler_ = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void register_crash_path(std::function<std::string()>&& crash_path_getter)
|
static void register_crash_path(std::function<std::string()>&& crash_path_getter)
|
||||||
@ -4486,6 +4493,10 @@ public:
|
|||||||
{
|
{
|
||||||
crash_use_handler_ = std::move(crash_use_handler);
|
crash_use_handler_ = std::move(crash_use_handler);
|
||||||
}
|
}
|
||||||
|
static void register_user_sig_handler(std::function<void(int sig)>&& user_sig_handler)
|
||||||
|
{
|
||||||
|
user_sig_handler_ = std::move(user_sig_handler);
|
||||||
|
}
|
||||||
SignalHandling(const std::vector<int>& = std::vector<int>())
|
SignalHandling(const std::vector<int>& = std::vector<int>())
|
||||||
: reporter_thread_([]() {
|
: reporter_thread_([]() {
|
||||||
/* We handle crashes in a utility thread:
|
/* We handle crashes in a utility thread:
|
||||||
@ -4605,9 +4616,12 @@ private:
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void signal_handler(int)
|
static inline void signal_handler(int sig)
|
||||||
{
|
{
|
||||||
crash_handler(signal_skip_recs);
|
crash_handler(signal_skip_recs);
|
||||||
|
if (user_sig_handler_) {
|
||||||
|
user_sig_handler_(sig);
|
||||||
|
}
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user