Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
9.2.2023: Due to updates GitLab will be unavailable for some minutes between 9:00 and 11:00.
Open sidebar
dcdb
dcdb
Commits
1c93c881
Commit
1c93c881
authored
Mar 24, 2015
by
Axel Auweter
Browse files
Add support for backtraces on crashes of CollectAgent.
parent
045703ef
Changes
4
Hide whitespace changes
Inline
Side-by-side
CollectAgent/Makefile
View file @
1c93c881
...
...
@@ -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)
...
...
CollectAgent/collectagent.cpp
View file @
1c93c881
...
...
@@ -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
"
;
exi
t
(
EXIT_FAILURE
);
abr
t
(
EXIT_FAILURE
,
INTERR
);
}
return
EXIT_SUCCESS
;
...
...
CollectAgent/simplemqttserverthread.cpp
View file @
1c93c881
...
...
@@ -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
"
;
exi
t
(
EXIT_FAILURE
);
abr
t
(
EXIT_FAILURE
,
INTERR
);
}
#ifdef SimpleMQTTVerbose
...
...
@@ -63,7 +64,7 @@ SimpleMQTTServerThread::~SimpleMQTTServerThread()
terminate
=
true
;
if
(
pthread_join
(
t
,
NULL
)
!=
0
)
{
cout
<<
"Error joining thread.
\n
"
;
exi
t
(
EXIT_FAILURE
);
abr
t
(
EXIT_FAILURE
,
INTERR
);
}
#ifdef SimpleMQTTVerbose
...
...
include/abrt.h
0 → 100644
View file @
1c93c881
/*
* 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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment