Fix: Improve the error reporting of the track/untrack command
authorMichael Jeanson <mjeanson@efficios.com>
Wed, 12 Aug 2015 20:08:16 +0000 (16:08 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 13 Aug 2015 19:27:41 +0000 (15:27 -0400)
This patch adds feedback when a track/untrack command is successful and
specific messages on errors. It also changes the behavior when tracking
an already tracked PID or untracking a PID that is not tracked from an
error to a warning with a successful exit code.

Fixes: #898
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/lttng/lttng-error.h
src/bin/lttng-sessiond/trace-ust.c
src/bin/lttng/commands/track-untrack.c
src/common/error.c

index efdca6520ce3e25bca295d66c2187eacf59f29b9..a7746fadff8cc8784fc40b1a813afbcc503157ff 100644 (file)
@@ -134,6 +134,8 @@ enum lttng_error_code {
        LTTNG_ERR_EXCLUSION_NOMEM        = 111, /* Lack of memory while processing event exclusions */
        LTTNG_ERR_INVALID_EVENT_NAME     = 112, /* Invalid event name */
        LTTNG_ERR_INVALID_CHANNEL_NAME   = 113, /* Invalid channel name */
+       LTTNG_ERR_PID_TRACKED            = 114, /* PID already tracked */
+       LTTNG_ERR_PID_NOT_TRACKED        = 115, /* PID not tracked */
 
        /* MUST be last element */
        LTTNG_ERR_NR,                           /* Last element */
index 248669616a3c4fc048bfb7ac2c47bde401fcbb15..3881084f04fb4024b14970120e44e85c02b1d59d 100644 (file)
@@ -656,7 +656,7 @@ int pid_tracker_add_pid(struct ust_pid_tracker *pid_tracker, int pid)
        tracker_node = pid_tracker_lookup(pid_tracker, pid, &iter);
        if (tracker_node) {
                /* Already exists. */
-               retval = LTTNG_ERR_INVALID;
+               retval = LTTNG_ERR_PID_TRACKED;
                goto end;
        }
        tracker_node = zmalloc(sizeof(*tracker_node));
@@ -684,7 +684,7 @@ int pid_tracker_del_pid(struct ust_pid_tracker *pid_tracker, int pid)
        tracker_node = pid_tracker_lookup(pid_tracker, pid, &iter);
        if (!tracker_node) {
                /* Not found */
-               retval = LTTNG_ERR_INVALID;
+               retval = LTTNG_ERR_PID_NOT_TRACKED;
                goto end;
        }
        ret = lttng_ht_del(pid_tracker->ht, &iter);
index 9ce850468d96db65fbe228e78e682b19bcd20cef..b3139c6931998003757d797991258881b79d02f9 100644 (file)
@@ -261,9 +261,28 @@ enum cmd_error_code track_untrack_pid(enum cmd_type cmd_type, const char *cmd_st
                DBG("%s PID %d", cmd_str, pid_list[i]);
                ret = lib_func(handle, pid_list[i]);
                if (ret) {
-                       success = 0;
-                       retval = CMD_ERROR;
+                       switch (-ret) {
+                       case LTTNG_ERR_PID_TRACKED:
+                               WARN("PID %i already tracked in session %s",
+                                               pid_list[i], session_name);
+                               success = 1;
+                               retval = CMD_SUCCESS;
+                               break;
+                       case LTTNG_ERR_PID_NOT_TRACKED:
+                               WARN("PID %i not tracked in session %s",
+                                               pid_list[i], session_name);
+                               success = 1;
+                               retval = CMD_SUCCESS;
+                               break;
+                       default:
+                               ERR("%s", lttng_strerror(ret));
+                               success = 0;
+                               retval = CMD_ERROR;
+                               break;
+                       }
                } else {
+                       MSG("PID %i %sed in session %s",
+                                       pid_list[i], cmd_str, session_name);
                        success = 1;
                }
 
index d3e3b949dc59184609e7c403cb888357bfd6f7c9..ad0ac51d4a5ad1af4611f1667a138e05b875c535 100644 (file)
@@ -167,6 +167,8 @@ static const char *error_string_array[] = {
        [ ERROR_INDEX(LTTNG_ERR_MI_NOT_IMPLEMENTED) ] = "Mi feature not implemented",
        [ ERROR_INDEX(LTTNG_ERR_INVALID_EVENT_NAME) ] = "Invalid event name",
        [ ERROR_INDEX(LTTNG_ERR_INVALID_CHANNEL_NAME) ] = "Invalid channel name",
+       [ ERROR_INDEX(LTTNG_ERR_PID_TRACKED) ] = "PID already tracked",
+       [ ERROR_INDEX(LTTNG_ERR_PID_NOT_TRACKED) ] = "PID not tracked",
 
        /* Last element */
        [ ERROR_INDEX(LTTNG_ERR_NR) ] = "Unknown error code"
This page took 0.027974 seconds and 4 git commands to generate.