From 23c2bd47c5ccd0e41e6f9e27fed5cdcfa0ed00f4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Thu, 6 Aug 2015 14:58:57 -0400 Subject: [PATCH] Add agent reply code logging helpers MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- src/bin/lttng-sessiond/agent.c | 38 ++++++++++++++++++++++++++++++++ src/common/sessiond-comm/agent.h | 1 + 2 files changed, 39 insertions(+) diff --git a/src/bin/lttng-sessiond/agent.c b/src/bin/lttng-sessiond/agent.c index c321ae41f..43acea42a 100644 --- a/src/bin/lttng-sessiond/agent.c +++ b/src/bin/lttng-sessiond/agent.c @@ -28,6 +28,44 @@ #include "agent.h" #include "ust-app.h" #include "utils.h" +#include "error.h" + +#define AGENT_RET_CODE_INDEX(code) (code - AGENT_RET_CODE_SUCCESS) + +/* + * Human readable agent return code. + */ +static const char *error_string_array[] = { + [ AGENT_RET_CODE_INDEX(AGENT_RET_CODE_SUCCESS) ] = "Success", + [ AGENT_RET_CODE_INDEX(AGENT_RET_CODE_INVALID) ] = "Invalid command", + [ AGENT_RET_CODE_INDEX(AGENT_RET_CODE_UNKNOWN_NAME) ] = "Unknown logger name", + + /* Last element */ + [ AGENT_RET_CODE_INDEX(AGENT_RET_CODE_NR) ] = "Unknown code", +}; + +static +void log_reply_code(uint32_t in_reply_ret_code) +{ + int level = PRINT_DBG3; + /* + * reply_ret_code and in_reply_ret_code are kept separate to have a + * sanitized value (used to retrieve the human readable string) and the + * original value which is logged as-is. + */ + uint32_t reply_ret_code = in_reply_ret_code; + + if (reply_ret_code < AGENT_RET_CODE_SUCCESS || + reply_ret_code >= AGENT_RET_CODE_NR) { + reply_ret_code = AGENT_RET_CODE_NR; + level = PRINT_ERR; + } + + LOG(level, "Agent replied with retcode: %s (%"PRIu32")", + error_string_array[AGENT_RET_CODE_INDEX( + reply_ret_code)], + in_reply_ret_code); +} /* * Match function for the events hash table lookup by name. diff --git a/src/common/sessiond-comm/agent.h b/src/common/sessiond-comm/agent.h index 93ef7ac09..574f8891f 100644 --- a/src/common/sessiond-comm/agent.h +++ b/src/common/sessiond-comm/agent.h @@ -40,6 +40,7 @@ enum lttcomm_agent_ret_code { AGENT_RET_CODE_SUCCESS = 1, AGENT_RET_CODE_INVALID = 2, AGENT_RET_CODE_UNKNOWN_NAME = 3, + AGENT_RET_CODE_NR, }; /* -- 2.34.1