From b193c53566334a10f0273258195beed78ee0524a Mon Sep 17 00:00:00 2001 From: Daniel Borkmann Date: Mon, 15 Oct 2012 13:33:37 +0200 Subject: [PATCH] die: apply checked format string, make const Signed-off-by: Daniel Borkmann --- src/die.h | 51 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/src/die.h b/src/die.h index 7160e49f..f45814f3 100644 --- a/src/die.h +++ b/src/die.h @@ -16,6 +16,19 @@ #include #include +#include "built_in.h" + +static inline void panic(const char *format, ...) __check_format_printf(1, 2); +static inline void syslog_panic(const char *format, + ...) __check_format_printf(1, 2); +static inline void syslog_maybe(int may, int priority, + const char *format, ...) __check_format_printf(3, 4); +static inline void whine(const char *format, ...) __check_format_printf(1, 2); +static inline void verbose_l1(const char *format, + ...) __check_format_printf(1, 2); +static inline void verbose_l2(const char *format, + ...) __check_format_printf(1, 2); + static inline void die(void) { exit(EXIT_FAILURE); @@ -26,37 +39,69 @@ static inline void _die(void) _exit(EXIT_FAILURE); } -static inline void panic(char *format, ...) +static inline void panic(const char *format, ...) { va_list vl; + va_start(vl, format); vfprintf(stderr, format, vl); va_end(vl); + die(); } static inline void syslog_panic(const char *format, ...) { va_list vl; + va_start(vl, format); vsyslog(LOG_ERR, format, vl); va_end(vl); + die(); } static inline void syslog_maybe(int may, int priority, const char *format, ...) { - if (may) { + if (!!may) { va_list vl; + va_start(vl, format); vsyslog(priority, format, vl); va_end(vl); } } -static inline void whine(char *format, ...) +static inline void whine(const char *format, ...) { va_list vl; + + va_start(vl, format); + vfprintf(stderr, format, vl); + va_end(vl); +} + +extern int verbose_level; + +static inline void verbose_l1(const char *format, ...) +{ + va_list vl; + + if (verbose_level < 1) + return; + + va_start(vl, format); + vfprintf(stderr, format, vl); + va_end(vl); +} + +static inline void verbose_l2(const char *format, ...) +{ + va_list vl; + + if (verbose_level < 2) + return; + va_start(vl, format); vfprintf(stderr, format, vl); va_end(vl); -- 2.11.4.GIT