From 1d0442da72fc734f12767ad019010ccb7e0d12cd Mon Sep 17 00:00:00 2001 From: Ralf Baechle Date: Mon, 17 Jun 2013 14:40:56 +0200 Subject: ax25ipd: Make LOGx() macros bulletproof. The LOGL1..LOGL4 macros were defined like: Now consider an invocation like: if (condition) LOGL1(...); else something_different(); CPP will expand this like: if (condition) if (loglevel>0) syslog(LOG_DAEMON | LOG_WARNING, ...); else something_different(); That is the else would now be considered associated with the wrong if. Macro arguments may also not have been evaluated on every invocation making the use of these function-like looking macros not function like. For example: LOGL1("%d", i++); would be expanded to if (loglevel>0) syslog(LOG_DAEMON | LOG_WARNING, i++); That is depending on the value of loglevel i++ would only be incremented if syslog was actually being called. Signed-off-by: Ralf Baechle --- ax25ipd/syslog.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 ax25ipd/syslog.c (limited to 'ax25ipd/syslog.c') diff --git a/ax25ipd/syslog.c b/ax25ipd/syslog.c new file mode 100644 index 0000000..493e21f --- /dev/null +++ b/ax25ipd/syslog.c @@ -0,0 +1,16 @@ +#include +#include + +#include "ax25ipd.h" + +void LOGLn(int level, const char *format, ...) +{ + va_list va; + + va_start(va, format); + + if (loglevel >= level) + vsyslog(LOG_DAEMON | LOG_WARNING, format, va); + + va_end(va); +} -- cgit v1.2.3