From 903ef6855b15a3352dee0d9870ca1b918669aa80 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Thu, 25 Aug 2016 16:43:13 -0400 Subject: [PATCH] Clean-up snapshot command error reporting MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- include/lttng/lttng-error.h | 3 ++- src/bin/lttng-sessiond/cmd.c | 29 ++++++++++++++--------------- src/bin/lttng/commands/snapshot.c | 3 --- src/common/error.c | 1 + 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/include/lttng/lttng-error.h b/include/lttng/lttng-error.h index df59f8f7b..db6fe73c2 100644 --- a/include/lttng/lttng-error.h +++ b/include/lttng/lttng-error.h @@ -143,7 +143,8 @@ enum lttng_error_code { LTTNG_ERR_PER_PID_SESSION = 120, /* Per-PID sessions unsupported */ LTTNG_ERR_KERN_CONTEXT_UNAVAILABLE = 121, /* Context unavailable on this kernel */ LTTNG_ERR_REGEN_STATEDUMP_FAIL = 122, /* Failed to regenerate the state dump */ - LTTNG_ERR_REGEN_STATEDUMP_NOMEM = 123, /* Failed to regenerate the state dump, not enough memory */ + LTTNG_ERR_REGEN_STATEDUMP_NOMEM = 123, /* Failed to regenerate the state dump, not enough memory */ + LTTNG_ERR_NOT_SNAPSHOT_SESSION = 124, /* Session is not in snapshot mode. */ /* MUST be last element */ LTTNG_ERR_NR, /* Last element */ diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 86c3c765c..916a73be2 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -3207,11 +3207,10 @@ int cmd_snapshot_add_output(struct ltt_session *session, DBG("Cmd snapshot add output for session %s", session->name); /* - * Permission denied to create an output if the session is not - * set in no output mode. + * Can't create an output if the session is not set in no-output mode. */ if (session->output_traces) { - ret = LTTNG_ERR_EPERM; + ret = LTTNG_ERR_NOT_SNAPSHOT_SESSION; goto error; } @@ -3275,7 +3274,7 @@ int cmd_snapshot_del_output(struct ltt_session *session, * set in no output mode. */ if (session->output_traces) { - ret = LTTNG_ERR_EPERM; + ret = LTTNG_ERR_NOT_SNAPSHOT_SESSION; goto error; } @@ -3327,19 +3326,19 @@ ssize_t cmd_snapshot_list_outputs(struct ltt_session *session, * set in no output mode. */ if (session->output_traces) { - ret = -LTTNG_ERR_EPERM; - goto error; + ret = -LTTNG_ERR_NOT_SNAPSHOT_SESSION; + goto end; } if (session->snapshot.nb_output == 0) { ret = 0; - goto error; + goto end; } list = zmalloc(session->snapshot.nb_output * sizeof(*list)); if (!list) { ret = -LTTNG_ERR_NOMEM; - goto error; + goto end; } /* Copy list from session to the new list object. */ @@ -3352,14 +3351,14 @@ ssize_t cmd_snapshot_list_outputs(struct ltt_session *session, if (lttng_strncpy(list[idx].name, output->name, sizeof(list[idx].name))) { ret = -LTTNG_ERR_INVALID; - goto error_unlock; + goto error; } if (output->consumer->type == CONSUMER_DST_LOCAL) { if (lttng_strncpy(list[idx].ctrl_url, output->consumer->dst.trace_path, sizeof(list[idx].ctrl_url))) { ret = -LTTNG_ERR_INVALID; - goto error_unlock; + goto error; } } else { /* Control URI. */ @@ -3367,7 +3366,7 @@ ssize_t cmd_snapshot_list_outputs(struct ltt_session *session, list[idx].ctrl_url, sizeof(list[idx].ctrl_url)); if (ret < 0) { ret = -LTTNG_ERR_NOMEM; - goto error_unlock; + goto error; } /* Data URI. */ @@ -3375,7 +3374,7 @@ ssize_t cmd_snapshot_list_outputs(struct ltt_session *session, list[idx].data_url, sizeof(list[idx].data_url)); if (ret < 0) { ret = -LTTNG_ERR_NOMEM; - goto error_unlock; + goto error; } } idx++; @@ -3384,10 +3383,10 @@ ssize_t cmd_snapshot_list_outputs(struct ltt_session *session, *outputs = list; list = NULL; ret = session->snapshot.nb_output; -error_unlock: - rcu_read_unlock(); error: + rcu_read_unlock(); free(list); +end: return ret; } @@ -3861,7 +3860,7 @@ int cmd_snapshot_record(struct ltt_session *session, * set in no output mode. */ if (session->output_traces) { - ret = LTTNG_ERR_EPERM; + ret = LTTNG_ERR_NOT_SNAPSHOT_SESSION; goto error; } diff --git a/src/bin/lttng/commands/snapshot.c b/src/bin/lttng/commands/snapshot.c index 00aa5b790..11cc2496a 100644 --- a/src/bin/lttng/commands/snapshot.c +++ b/src/bin/lttng/commands/snapshot.c @@ -579,9 +579,6 @@ int cmd_snapshot(int argc, const char **argv) command_ret = handle_command(poptGetArgs(pc)); if (command_ret) { switch (-command_ret) { - case LTTNG_ERR_EPERM: - ERR("The session needs to be set in no output mode (--no-output)"); - break; case LTTNG_ERR_SNAPSHOT_NODATA: WARN("%s", lttng_strerror(command_ret)); diff --git a/src/common/error.c b/src/common/error.c index 1067e4852..938932cdc 100644 --- a/src/common/error.c +++ b/src/common/error.c @@ -185,6 +185,7 @@ static const char *error_string_array[] = { [ ERROR_INDEX(LTTNG_ERR_KERN_CONTEXT_UNAVAILABLE) ] = "Context unavailable on this kernel", [ ERROR_INDEX(LTTNG_ERR_REGEN_STATEDUMP_FAIL) ] = "Failed to regenerate the state dump", [ ERROR_INDEX(LTTNG_ERR_REGEN_STATEDUMP_NOMEM) ] = "Failed to regenerate the state dump, not enough memory", + [ ERROR_INDEX(LTTNG_ERR_NOT_SNAPSHOT_SESSION) ] = "Snapshot command can't be applied to a non-snapshot session", /* Last element */ [ ERROR_INDEX(LTTNG_ERR_NR) ] = "Unknown error code" -- 2.34.1