diff options
-rw-r--r-- | tools/log.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/tools/log.c b/tools/log.c index 05ff96f..4ae4aed 100644 --- a/tools/log.c +++ b/tools/log.c @@ -26,13 +26,14 @@ #include "kmod.h" +#define PRIO_MAX_SIZE 32 + static bool log_use_syslog; static int log_priority = LOG_ERR; -static _always_inline_ const char *prio_to_str(int prio) +static const char *prio_to_str(char buf[static PRIO_MAX_SIZE], int prio) { const char *prioname; - char buf[32]; switch (prio) { case LOG_CRIT: @@ -54,7 +55,7 @@ static _always_inline_ const char *prio_to_str(int prio) prioname = "DEBUG"; break; default: - snprintf(buf, sizeof(buf), "LOG-%03d", prio); + snprintf(buf, PRIO_MAX_SIZE, "LOG-%03d", prio); prioname = buf; } @@ -65,9 +66,12 @@ _printf_format_(6, 0) static void log_kmod(void *data, int priority, const char *file, int line, const char *fn, const char *format, va_list args) { - const char *prioname = prio_to_str(priority); + char buf[PRIO_MAX_SIZE]; + const char *prioname; char *str; + prioname = prio_to_str(buf, priority); + if (vasprintf(&str, format, args) < 0) return; @@ -108,6 +112,7 @@ void log_close(void) void log_printf(int prio, const char *fmt, ...) { + char buf[PRIO_MAX_SIZE]; const char *prioname; char *msg; va_list args; @@ -122,7 +127,7 @@ void log_printf(int prio, const char *fmt, ...) if (msg == NULL) return; - prioname = prio_to_str(prio); + prioname = prio_to_str(buf, prio); if (log_use_syslog) syslog(prio, "%s: %s", prioname, msg); |