From bb9d17a5c3f57212d92bf18b01ce87dedad2951a Mon Sep 17 00:00:00 2001 From: fanyang Date: Mon, 30 Sep 2019 16:46:37 +0800 Subject: [PATCH] lib/log: passing va_list to user-provided log call va_list is not passed in logfunc, so the user-provided log call can't get the arguments corresponding to the format string. This patch fixes it and replaces log func pointer in spdk_app_opts with logfunc. Change-Id: I7f7806f47c4fd8f36f3234aa5a8c877db0fc7140 Signed-off-by: Yang Fan Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/469828 Reviewed-by: Feng,Li Reviewed-by: Darek Stojaczyk Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto Tested-by: SPDK CI Jenkins --- include/spdk/event.h | 9 +-------- include/spdk/log.h | 12 +++++++++++- lib/log/log.c | 4 +++- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/include/spdk/event.h b/include/spdk/event.h index b5e53c77c9..35eaedef11 100644 --- a/include/spdk/event.h +++ b/include/spdk/event.h @@ -135,15 +135,8 @@ struct spdk_app_opts { /** * for passing user-provided log call - * - * \param level Log level threshold. - * \param file Name of the current source file. - * \param line Current source file line. - * \param func Current source function name. - * \param format Format string to the message. */ - void (* log)(int level, const char *file, const int line, - const char *func, const char *format); + logfunc *log; }; diff --git a/include/spdk/log.h b/include/spdk/log.h index bc718618f0..d281c71b84 100644 --- a/include/spdk/log.h +++ b/include/spdk/log.h @@ -45,8 +45,18 @@ extern "C" { #endif +/** + * for passing user-provided log call + * + * \param level Log level threshold. + * \param file Name of the current source file. + * \param line Current source file line. + * \param func Current source function name. + * \param format Format string to the message. + * \param args Additional arguments for format string. + */ typedef void logfunc(int level, const char *file, const int line, - const char *func, const char *format); + const char *func, const char *format, va_list args); /** * Initialize the logging module. Messages prior diff --git a/lib/log/log.c b/lib/log/log.c index 0939754899..c6f6857c3d 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -117,7 +117,9 @@ spdk_log(enum spdk_log_level level, const char *file, const int line, const char va_list ap; if (g_log) { - g_log(level, file, line, func, format); + va_start(ap, format); + g_log(level, file, line, func, format, ap); + va_end(ap); return; }