Commit 1c93c881 authored by Axel Auweter's avatar Axel Auweter
Browse files

Add support for backtraces on crashes of CollectAgent.

parent 045703ef
......@@ -14,7 +14,7 @@ P = $(shell cd $(DCDBDEPLOYPATH)/lib/ && pwd)
U = $(shell uname)
$(TARGET): $(OBJS)
$(CXX) -o $(TARGET) $(OBJS) $(LIBS)
$(CXX) $(CXXFLAGS) -o $(TARGET) $(OBJS) $(LIBS)
all: $(TARGET)
......
......@@ -17,6 +17,7 @@
#include "simplemqttserver.h"
#include "messaging.h"
#include "abrt.h"
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
......@@ -29,12 +30,18 @@ uint64_t pmsgCtr;
SensorDataStore *mySensorDataStore;
std::string host;
/* Normal termination (SIGINT, CTRL+C) */
void sigHandler(int sig)
{
keepRunning = 0;
}
/* Crash */
void abrtHandler(int sig)
{
abrt(EXIT_FAILURE, SIGNAL);
}
void mqttCallback(SimpleMQTTMessage *msg)
{
/*
......@@ -129,6 +136,13 @@ int main(int argc, char* const argv[]) {
*/
signal(SIGINT, sigHandler);
/*
* Catch critical signals to allow for backtraces
*/
signal(SIGABRT, abrtHandler);
signal(SIGSEGV, abrtHandler);
signal(SIGTERM, abrtHandler);
/* Parse command line */
char ret;
host="localhost";
......@@ -187,7 +201,7 @@ int main(int argc, char* const argv[]) {
}
catch (const exception& e) {
cout << "Exception: " << e.what() << "\n";
exit(EXIT_FAILURE);
abrt(EXIT_FAILURE, INTERR);
}
return EXIT_SUCCESS;
......
......@@ -6,6 +6,7 @@
*/
#include "simplemqttserver.h"
#include "abrt.h"
using namespace std;
using namespace boost::system;
......@@ -44,7 +45,7 @@ SimpleMQTTServerThread::SimpleMQTTServerThread()
terminate = false;
if (pthread_create(&t, NULL, launch, this) != 0) {
cout << "Error creating new MQTT server thread.\n";
exit(EXIT_FAILURE);
abrt(EXIT_FAILURE, INTERR);
}
#ifdef SimpleMQTTVerbose
......@@ -63,7 +64,7 @@ SimpleMQTTServerThread::~SimpleMQTTServerThread()
terminate = true;
if (pthread_join(t, NULL) != 0) {
cout << "Error joining thread.\n";
exit(EXIT_FAILURE);
abrt(EXIT_FAILURE, INTERR);
}
#ifdef SimpleMQTTVerbose
......
/*
* abrt.h
*
* Created on: Mar 24, 2015
* Author: Axel Auweter
*/
#include <stdio.h>
#include <execinfo.h>
#ifndef ABRT_H
#define ABRT_H
#define STACKTRACE_DEPTH 20
typedef enum {
SIGNAL,
INTERR
} AbrtSrc;
/* Abort handler that prints out a stack trace */
static inline void abrt(int exitcode, AbrtSrc source)
{
void* fcn_ptr[STACKTRACE_DEPTH];
size_t fcn_ptr_num_elems;
fcn_ptr_num_elems = backtrace(fcn_ptr, STACKTRACE_DEPTH);
fprintf(stderr, "Program abort due to %s. Backtrace:\n",
source == SIGNAL ? "signal" :
source == INTERR ? "internal error" :
"unknown error"
);
backtrace_symbols_fd(fcn_ptr, fcn_ptr_num_elems, STDERR_FILENO);
exit(exitcode);
}
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment