#5 install sig handler

pull/32/head
Geoffrey Merck 4 years ago
parent a150b9d35c
commit f0a4320928

@ -23,6 +23,11 @@
#include <string>
#include <iostream>
#include <vector>
#include <stdio.h>
#include <execinfo.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include "DStarGatewayDefs.h"
#include "DStarGatewayConfig.h"
@ -41,9 +46,15 @@
#include "APRSGPSDIdFrameProvider.h"
#include "APRSFixedIdFrameProvider.h"
#ifndef UNIT_TESTS
#ifdef UNIT_TESTS
int fakemain(int argc, char *argv[])
#else
int main(int argc, char *argv[])
#endif
{
// install sigHandler
signal(SIGSEGV, __sigHandler);
setbuf(stdout, NULL);
if (2 != argc) {
printf("usage: %s path_to_config_file\n", argv[0]);
@ -70,7 +81,21 @@ int main(int argc, char *argv[])
return 0;
}
#endif
void __sigHandler(int sig)
{
if(sig == SIGSEGV) {
void *array[100];
size_t size;
// get void*'s for all entries on the stack
size = backtrace(array, 100);
// print out all the frames to stderr
fprintf(stderr, "Error: signal %d:\n", sig);
backtrace_symbols_fd(array, size, STDERR_FILENO);
exit(1);
}
}
CDStarGatewayApp::CDStarGatewayApp(const std::string &configFile) : m_configFile(configFile), m_thread(NULL)
{

@ -21,6 +21,8 @@
#include "DStarGatewayThread.h"
void __sigHandler(int sig);
class CDStarGatewayApp
{
private:

@ -23,7 +23,7 @@ export LOG_DIR=/var/log/dstargateway/
ifeq ($(ENABLE_DEBUG), 1)
# choose this if you want debugging help
export CPPFLAGS=-g -ggdb -W -Wall -Werror -std=c++17
export CPPFLAGS=-g -rdynamic -ggdb -W -Wall -Werror -std=c++17
else
# or, you can choose this for a much smaller executable without debugging help
CPPFLAGS=-W -O3 -Wall -Werror -std=c++17

Loading…
Cancel
Save

Powered by TurnKey Linux.