Skip to content

Commit

Permalink
Use boost:stacktrace for sig_handler
Browse files Browse the repository at this point in the history
  • Loading branch information
kingster committed May 5, 2021
1 parent a8ecad3 commit 5ffe6fa
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions orkaudio/OrkAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#include <iostream>
#include "stdio.h"

#define BOOST_STACKTRACE_USE_ADDR2LINE
#include <boost/stacktrace.hpp>

#include "MultiThreadedServer.h"
#include "OrkAudio.h"
#include "Utils.h"
Expand Down Expand Up @@ -60,6 +63,8 @@
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <cstdlib> // std::abort
#include <iostream> // std::cerr
#endif

static volatile bool serviceStop = false;
Expand Down Expand Up @@ -401,27 +406,20 @@ void MainThread()
OrkLogManager::Instance()->Shutdown();
}

void handler(int sig) {
#ifdef linux

void *array[10];
size_t size;

// get void*'s for all entries on the stack
size = backtrace(array, 10);

void sig_handler(int sig) {
// print out all the frames to stderr
fprintf(stderr, "Error: signal %d:\n", sig);
backtrace_symbols_fd(array, size, STDERR_FILENO);
#endif
try {
std::cerr << boost::stacktrace::stacktrace();
} catch (...) {}
exit(1);
}


int main(int argc, char* argv[])
{
signal(SIGSEGV, handler); // install fatal error handler

signal(SIGSEGV, sig_handler); // install fatal error handler
signal(SIGABRT, sig_handler); // install abort error handler

OrkAprSingleton::Initialize();

// the "service name" reported on the tape messages uses CONFIG.m_serviceName
Expand Down

0 comments on commit 5ffe6fa

Please sign in to comment.