X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fagent.c;h=ca2d4c872931632f4e5d46cb9c6b17b6b3d0d8ed;hp=c321ae41f0987c42a308ba3311b381eb4237ceff;hb=ab21818442628467073e8d2b303f6d5d78a090f5;hpb=b26d1f5c53927cf45d381af27f955019850f2d87 diff --git a/src/bin/lttng-sessiond/agent.c b/src/bin/lttng-sessiond/agent.c index c321ae41f..ca2d4c872 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. @@ -235,6 +273,7 @@ static ssize_t list_events(struct agent_app *app, struct lttng_event **events) int ret, i, len = 0, offset = 0; uint32_t nb_event; size_t data_size; + uint32_t reply_ret_code; struct lttng_event *tmp_events = NULL; struct lttcomm_agent_list_reply *reply = NULL; struct lttcomm_agent_list_reply_hdr reply_hdr; @@ -257,14 +296,14 @@ static ssize_t list_events(struct agent_app *app, struct lttng_event **events) goto error_io; } - switch (be32toh(reply_hdr.ret_code)) { + reply_ret_code = be32toh(reply_hdr.ret_code); + log_reply_code(reply_ret_code); + switch (reply_ret_code) { case AGENT_RET_CODE_SUCCESS: data_size = be32toh(reply_hdr.data_size) + sizeof(*reply); break; default: - ERR("Agent returned an unknown code: %" PRIu32, - be32toh(reply_hdr.ret_code)); - ret = LTTNG_ERR_FATAL; + ret = LTTNG_ERR_UNK; goto error; } @@ -320,6 +359,7 @@ static int enable_event(struct agent_app *app, struct agent_event *event) { int ret; uint64_t data_size; + uint32_t reply_ret_code; struct lttcomm_agent_enable msg; struct lttcomm_agent_generic_reply reply; @@ -351,16 +391,16 @@ static int enable_event(struct agent_app *app, struct agent_event *event) goto error_io; } - switch (be32toh(reply.ret_code)) { + reply_ret_code = be32toh(reply.ret_code); + log_reply_code(reply_ret_code); + switch (reply_ret_code) { case AGENT_RET_CODE_SUCCESS: break; case AGENT_RET_CODE_UNKNOWN_NAME: ret = LTTNG_ERR_UST_EVENT_NOT_FOUND; goto error; default: - ERR("Agent returned an unknown code: %" PRIu32, - be32toh(reply.ret_code)); - ret = LTTNG_ERR_FATAL; + ret = LTTNG_ERR_UNK; goto error; } @@ -382,6 +422,7 @@ static int disable_event(struct agent_app *app, struct agent_event *event) { int ret; uint64_t data_size; + uint32_t reply_ret_code; struct lttcomm_agent_disable msg; struct lttcomm_agent_generic_reply reply; @@ -411,16 +452,16 @@ static int disable_event(struct agent_app *app, struct agent_event *event) goto error_io; } - switch (be32toh(reply.ret_code)) { + reply_ret_code = be32toh(reply.ret_code); + log_reply_code(reply_ret_code); + switch (reply_ret_code) { case AGENT_RET_CODE_SUCCESS: break; case AGENT_RET_CODE_UNKNOWN_NAME: ret = LTTNG_ERR_UST_EVENT_NOT_FOUND; goto error; default: - ERR("Agent returned an unknown code: %" PRIu32, - be32toh(reply.ret_code)); - ret = LTTNG_ERR_FATAL; + ret = LTTNG_ERR_UNK; goto error; } @@ -675,10 +716,7 @@ void agent_add_app(struct agent_app *app) assert(app); DBG3("Agent adding app sock: %d and pid: %d to ht", app->sock->fd, app->pid); - - rcu_read_lock(); lttng_ht_add_unique_ulong(agent_apps_ht_by_sock, &app->node); - rcu_read_unlock(); } /* @@ -751,9 +789,7 @@ void agent_add(struct agent *agt, struct lttng_ht *ht) DBG3("Agent adding from domain %d", agt->domain); - rcu_read_lock(); lttng_ht_add_unique_u64(ht, &agt->node); - rcu_read_unlock(); } /* @@ -917,6 +953,7 @@ void agent_destroy_event(struct agent_event *event) assert(event); free(event->filter); + free(event->filter_expression); free(event); }