assert.c 940 Bytes
Newer Older
1
#include <string.h>
2 3 4
#include <stdarg.h>
#include <assert.h>
#include <wrc.h>
5 6 7 8 9 10 11 12
#include "ipv4.h"

#ifdef CONFIG_SYSLOG
#  define HAS_SYSLOG 1
#else
#  define HAS_SYSLOG 0
#endif

13 14 15 16

void panic(const char *fmt, ...)
{
	va_list args;
17 18 19 20 21 22
	char message[128];

	strcpy(message, "Panic: ");
	va_start(args, fmt);
	pp_vsprintf(message + 7, fmt, args);
	va_end(args);
23

24 25
	if (HAS_SYSLOG)
		syslog_report(message);
26
	while (1) {
27
		pp_printf(message);
28 29 30 31 32 33 34 35
		usleep(1000 * 1000);
	}
}

void __assert(const char *func, int line, int forever,
		     const char *fmt, ...)
{
	va_list args;
36 37 38 39 40 41 42 43 44 45
	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);
	}
46

47 48
	if (HAS_SYSLOG)
		syslog_report(message);
49
	while (1) {
50
		pp_printf(message);
51 52 53 54 55
		if (!forever)
			break;
		usleep(1000 * 1000);
	}
}