From a4a709c1868a4b2ad08bf975fc4cb67024477b8c Mon Sep 17 00:00:00 2001 From: "Fabio M. Di Nitto" Date: Thu, 20 Dec 2018 05:48:18 +0100 Subject: [PATCH] [libknet] logging: add handle information in log structure Use case: an app is using the same fd to gather logs from multiple knet_h, the app might still require to know which knet_h has generated the log for better logging purposes. Signed-off-by: Fabio M. Di Nitto --- libknet/libknet.h | 1 + libknet/logging.c | 1 + libknet/tests/test-common.c | 9 +++++++++ 3 files changed, 11 insertions(+) diff --git a/libknet/libknet.h b/libknet/libknet.h index ae2a5df47..50f1dc443 100644 --- a/libknet/libknet.h +++ b/libknet/libknet.h @@ -1921,6 +1921,7 @@ struct knet_log_msg { char msg[KNET_MAX_LOG_MSG_SIZE]; uint8_t subsystem; /* KNET_SUB_* */ uint8_t msglevel; /* KNET_LOG_* */ + knet_handle_t knet_h; /* pointer to the handle generating the log */ }; /** diff --git a/libknet/logging.c b/libknet/logging.c index 14c6eff5d..4587f086a 100644 --- a/libknet/logging.c +++ b/libknet/logging.c @@ -221,6 +221,7 @@ void log_msg(knet_handle_t knet_h, uint8_t subsystem, uint8_t msglevel, memset(&msg, 0, sizeof(struct knet_log_msg)); msg.subsystem = subsystem; msg.msglevel = msglevel; + msg.knet_h = knet_h; va_start(ap, fmt); #ifdef __clang__ diff --git a/libknet/tests/test-common.c b/libknet/tests/test-common.c index a0efe908c..9622ebcd1 100644 --- a/libknet/tests/test-common.c +++ b/libknet/tests/test-common.c @@ -233,6 +233,15 @@ void flush_logs(int logfd, FILE *std) bytes_read += len; } + if (!msg.knet_h) { + /* + * this is harsh but this function is void + * and it is used also inside log_thread. + * this is the easiest to get out with an error + */ + fprintf(std, "NO HANDLE INFO IN LOG MSG!!\n"); + abort(); + } fprintf(std, "[knet]: [%s] %s: %.*s\n", knet_log_get_loglevel_name(msg.msglevel), knet_log_get_subsystem_name(msg.subsystem),