From: Michael Jeanson Date: Wed, 12 Aug 2015 20:08:16 +0000 (-0400) Subject: Fix: Improve the error reporting of the track/untrack command X-Git-Tag: v2.8.0-rc1~484 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=b93a4a13a2724a73069e1d661df5df83c629bb36;p=lttng-tools.git Fix: Improve the error reporting of the track/untrack command 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 Signed-off-by: Jérémie Galarneau --- diff --git a/include/lttng/lttng-error.h b/include/lttng/lttng-error.h index efdca6520..a7746fadf 100644 --- a/include/lttng/lttng-error.h +++ b/include/lttng/lttng-error.h @@ -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 */ diff --git a/src/bin/lttng-sessiond/trace-ust.c b/src/bin/lttng-sessiond/trace-ust.c index 248669616..3881084f0 100644 --- a/src/bin/lttng-sessiond/trace-ust.c +++ b/src/bin/lttng-sessiond/trace-ust.c @@ -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); diff --git a/src/bin/lttng/commands/track-untrack.c b/src/bin/lttng/commands/track-untrack.c index 9ce850468..b3139c693 100644 --- a/src/bin/lttng/commands/track-untrack.c +++ b/src/bin/lttng/commands/track-untrack.c @@ -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; } diff --git a/src/common/error.c b/src/common/error.c index d3e3b949d..ad0ac51d4 100644 --- a/src/common/error.c +++ b/src/common/error.c @@ -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"