Clean-up snapshot command error reporting
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 25 Aug 2016 20:43:13 +0000 (16:43 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 25 Aug 2016 21:01:38 +0000 (17:01 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/lttng/lttng-error.h
src/bin/lttng-sessiond/cmd.c
src/bin/lttng/commands/snapshot.c
src/common/error.c

index df59f8f7b04c77f1a29e9fc09b160aab04d93f68..db6fe73c27741c2b269063519adda358bd91fea9 100644 (file)
@@ -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 */
index 86c3c765c8dfb2173137894a4fceffb156515ce9..916a73be2fa8990f2317a49ca09c418e998e9619 100644 (file)
@@ -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;
        }
 
index 00aa5b790448e57d3a26d1b8f838bd51d6acf564..11cc2496a2b61e649661df782a8da66fc375b30b 100644 (file)
@@ -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));
 
index 1067e48527e8d3fc70a46cd3766d26bc8d475f8d..938932cdc7b5cbd6ab03a1789cf9330712a8b5f2 100644 (file)
@@ -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"
This page took 0.031604 seconds and 4 git commands to generate.