Commit 74aa649b authored by Alessandro Rubini's avatar Alessandro Rubini Committed by Adam Wujek

lib/assert: report to syslog if syslog is there

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 9336a054
#include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include <assert.h> #include <assert.h>
#include <wrc.h> #include <wrc.h>
#include "ipv4.h"
#ifdef CONFIG_SYSLOG
# define HAS_SYSLOG 1
#else
# define HAS_SYSLOG 0
#endif
void panic(const char *fmt, ...) void panic(const char *fmt, ...)
{ {
va_list args; va_list args;
char message[128];
strcpy(message, "Panic: ");
va_start(args, fmt);
pp_vsprintf(message + 7, fmt, args);
va_end(args);
if (HAS_SYSLOG)
syslog_report(message);
while (1) { while (1) {
pp_printf("Panic: "); pp_printf(message);
va_start(args, fmt);
vprintf(fmt, args);
va_end(args);
usleep(1000 * 1000); usleep(1000 * 1000);
} }
} }
...@@ -19,17 +33,21 @@ void __assert(const char *func, int line, int forever, ...@@ -19,17 +33,21 @@ void __assert(const char *func, int line, int forever,
const char *fmt, ...) const char *fmt, ...)
{ {
va_list args; va_list args;
char message[200];
int more = fmt && fmt[0];
pp_sprintf(message, "Assertion failed (%s:%i)%s", func, line,
more ? ": " : "\n");
if (more) {
va_start(args, fmt);
pp_vsprintf(message + strlen(message), fmt, args);
va_end(args);
}
if (HAS_SYSLOG)
syslog_report(message);
while (1) { while (1) {
pp_printf("Assertion failed (%s:%i)", func, line); pp_printf(message);
if (fmt && fmt[0]) {
pp_printf(": ");
va_start(args, fmt);
vprintf(fmt, args);
va_end(args);
} else {
pp_printf(".\n");
}
if (!forever) if (!forever)
break; break;
usleep(1000 * 1000); usleep(1000 * 1000);
......
Markdown is supported
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