From: Jérémie Galarneau Date: Thu, 6 Aug 2015 18:58:57 +0000 (-0400) Subject: Add agent reply code logging helpers X-Git-Tag: v2.8.0-rc1~517 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=23c2bd47c5ccd0e41e6f9e27fed5cdcfa0ed00f4;p=lttng-tools.git Add agent reply code logging helpers Signed-off-by: Jérémie Galarneau --- 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, }; /*