From 98e87c8628f9b0a0a96bc46879b65a78b756a718 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sun, 20 Dec 1998 14:24:35 +0000 Subject: Finer grained logging levels: #define L_DEBUG "\001" /* Debugging messages */ #define L_INFO "\002" /* Informational messages */ #define L_WARN "\003" /* Warnings */ #define L_ERR "\004" /* Errors */ #define L_AUTH "\005" /* Authorization failed etc. */ #define L_FATAL "\006" /* Fatal errors */ #define L_TRACE "\002" /* Protocol tracing */ #define L_INFO "\003" /* Informational messages */ #define L_REMOTE "\004" /* Remote protocol errors */ #define L_WARN "\004" /* Local warnings */ #define L_ERR "\005" /* Local errors */ #define L_AUTH "\006" /* Authorization failed etc. */ #define L_FATAL "\007" /* Fatal errors */ #define L_BUG "\010" /* BIRD bugs */ Introduced bug() which is like die(), but with level L_BUG. Protocols should _never_ call die() as it should be used only during initialization and on irrecoverable catastrophic events like out of memory. Also introduced ASSERT() which behaves like normal assert(), but it calls bug() when assertion fails. When !defined(DEBUGGING), it gets ignored. --- TODO | 8 +++++--- lib/birdlib.h | 20 +++++++++++++++----- sysdep/unix/log.c | 14 ++++++++++++-- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/TODO b/TODO index 476506fd..2d4cbab6 100644 --- a/TODO +++ b/TODO @@ -1,12 +1,12 @@ Core ~~~~ * right usage of DBG vs. debug -* cleanup debugging calls! +* cleanup debugging calls +* logging and tracing; use appropriate log levels +* check log calls for trailing newlines - TOS not supported by kernel -> automatically drop routes with TOS<>0 -- use -freg-struct-return ? - - fake multipath? - replace all NUM's by expr's - config file: define ipaddr constants? @@ -25,6 +25,8 @@ Core - static: check validity of route destination? - static: device routes +- device: configuration of interface patterns + - filter: logging of dropped routes (?) - limitation of memory consumption: per-process and total (?) - adding of route: check whether all bits not covered by masklen are zero diff --git a/lib/birdlib.h b/lib/birdlib.h index 4b8164bd..f377a99b 100644 --- a/lib/birdlib.h +++ b/lib/birdlib.h @@ -27,13 +27,17 @@ void log(char *msg, ...); void die(char *msg, ...) NORET; +void bug(char *msg, ...) NORET; #define L_DEBUG "\001" /* Debugging messages */ -#define L_INFO "\002" /* Informational messages */ -#define L_WARN "\003" /* Warnings */ -#define L_ERR "\004" /* Errors */ -#define L_AUTH "\005" /* Authorization failed etc. */ -#define L_FATAL "\006" /* Fatal errors */ +#define L_TRACE "\002" /* Protocol tracing */ +#define L_INFO "\003" /* Informational messages */ +#define L_REMOTE "\004" /* Remote protocol errors */ +#define L_WARN "\004" /* Local warnings */ +#define L_ERR "\005" /* Local errors */ +#define L_AUTH "\006" /* Authorization failed etc. */ +#define L_FATAL "\007" /* Fatal errors */ +#define L_BUG "\010" /* BIRD bugs */ void log_init(char *); /* Initialize logging to given file (NULL=stderr, ""=syslog) */ void log_init_debug(char *); /* Initialize debug dump to given file (NULL=stderr, ""=off) */ @@ -48,4 +52,10 @@ void debug(char *msg, ...); /* Printf to debug output */ #define DBG(x, y...) #endif +#ifdef DEBUGGING +#define ASSERT(x) do { if (!(x)) bug("Assertion `%s' failed at %s:%d", #x, __FILE__, __LINE__); } while(0) +#else +#define ASSERT(x) do { } while(0) +#endif + #endif diff --git a/sysdep/unix/log.c b/sysdep/unix/log.c index 00589a3c..5dd7ef7f 100644 --- a/sysdep/unix/log.c +++ b/sysdep/unix/log.c @@ -107,19 +107,29 @@ log(char *msg, ...) va_list args; va_start(args, msg); - if (*msg >= 1 && *msg <= 6) + if (*msg >= 1 && *msg <= 8) class = *msg++; vlog(class, msg, args); va_end(args); } +void +bug(char *msg, ...) +{ + va_list args; + + va_start(args, msg); + vlog(L_BUG[0], msg, args); + exit(1); +} + void die(char *msg, ...) { va_list args; va_start(args, msg); - vlog(6, msg, args); + vlog(L_FATAL[0], msg, args); exit(1); } -- cgit v1.2.3