Add agent reply code logging helpers
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 6 Aug 2015 18:58:57 +0000 (14:58 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 6 Aug 2015 19:05:28 +0000 (15:05 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/agent.c
src/common/sessiond-comm/agent.h

index c321ae41f0987c42a308ba3311b381eb4237ceff..43acea42a85ca4f4b1c00c8e2a5a409904cd1582 100644 (file)
 #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.
index 93ef7ac093e2fe241b44d31c5a6a4640ca35911c..574f8891f20bc8211e1160e3038d2c97ec1b9707 100644 (file)
@@ -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,
 };
 
 /*
This page took 0.027064 seconds and 4 git commands to generate.