add errorexit function to print error message, backtrace and exit application

test16bit
Steffen Pohle 3 years ago
parent b77a3d7509
commit aeb43f5a46

@ -8,6 +8,7 @@
#include <string>
#include <list>
#include "simpleskycam.h"
#include "videodev.h"
#include "json.h"

@ -5,7 +5,9 @@
*****************************************************************************************/
#include <sys/time.h>
#include <execinfo.h>
#include "simpleskycam.h"
#include "config.h"
#include "configuration.h"
#include "gui.h"
@ -32,7 +34,7 @@ int main (int argc, char **argv) {
char buffer[16];
setvbuf (stdout, buffer, _IONBF, 16);
#endif
printf ("SimpleSkyCam - %s\n", VERSION);
printf (" written by Steffen Pohle <steffen@gulpe.de>\n");
printf ("\n");
@ -88,3 +90,39 @@ float get_cycletime(struct timeval *t) {
return f;
}
/*
* print error message and the backtrace
*/
#define SIZE 100
void errorexit (char *fmt,...) {
//
// error message
va_list args;
char text[4096];
va_start (args, fmt);
vsnprintf (text, 4096, fmt, args);
va_end (args);
printf ("***************************\n");
printf (" ERROR\n");
printf ("***************************\n");
printf ("%s", text);
//
// backtrace
int j, nptrs;
void *buffer[SIZE];
char **s;
nptrs = backtrace(buffer, SIZE);
if ((s = (char**) backtrace_symbols(buffer, nptrs)) == NULL) {
for (j = 0; j < nptrs; j++) printf ("%-5d %p\n", j, buffer[j]);
}
else {
for (j = 0; j < nptrs; j++) printf ("%-5d %s\n", j, s[j]);
}
exit (-1);
}

Loading…
Cancel
Save