From fbbca2c5076a489ee4ae643d6d9199ca5085be95 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 3 Sep 2020 22:03:22 +0200 Subject: [PATCH] libmultipath: prototype implementation of log_oom() Rationale: with VERBOSE_OOM_LOGGING, we log the part of the code where OOM occured, with minimal runtime effort (no string formatting). With lots of log_oom() invocations, our binary will increase by many static strings. Without VERBOSE_OOM_LOGGING, we just print a minimal error message, which will be enough most of the time. Signed-off-by: Martin Wilck --- libmultipath/debug.c | 7 +++++++ libmultipath/debug.h | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/libmultipath/debug.c b/libmultipath/debug.c index 4128cb9..9062581 100644 --- a/libmultipath/debug.c +++ b/libmultipath/debug.c @@ -48,3 +48,10 @@ void dlog (int sink, int prio, const char * fmt, ...) } va_end(ap); } + +#ifndef VERBOSE_OOM_LOGGING +void log_oom(void) +{ + condlog(0, "Out of memory"); +} +#endif diff --git a/libmultipath/debug.h b/libmultipath/debug.h index c6120c1..f61ecb6 100644 --- a/libmultipath/debug.h +++ b/libmultipath/debug.h @@ -11,3 +11,11 @@ extern int logsink; #define condlog(prio, fmt, args...) \ dlog(logsink, prio, fmt "\n", ##args) + +#ifdef VERBOSE_OOM_LOGGING +#define __log_oom(file, line) condlog(0, "Out of memory in " file ":" #line) +#define _log_oom(file, line) __log_oom(file, line) +#define log_oom() _log_oom(__FILE__, __LINE__) +#else +void log_oom(void); +#endif -- 2.28.0