<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 12, 2015 at 4:08 PM, Michael Jeanson <span dir="ltr"><<a href="mailto:mjeanson@efficios.com" target="_blank">mjeanson@efficios.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This patch adds feedback when a track/untrack command is successful and<br>
specific messages on errors. It also changes the behavior when tracking<br>
an already tracked PID or untracking a PID that is not tracked from an<br>
error to a warning with a successful exit code.<br>
<br>
Fixes: #898<br>
<br>
Signed-off-by: Michael Jeanson <<a href="mailto:mjeanson@efficios.com">mjeanson@efficios.com</a>><br>
---<br>
 include/lttng/lttng-error.h            |  2 ++<br>
 src/bin/lttng-sessiond/trace-ust.c     |  4 ++--<br>
 src/bin/lttng/commands/track-untrack.c | 23 +++++++++++++++++++++--<br>
 src/common/error.c                     |  2 ++<br>
 4 files changed, 27 insertions(+), 4 deletions(-)<br>
<br>
diff --git a/include/lttng/lttng-error.h b/include/lttng/lttng-error.h<br>
index efdca65..a7746fa 100644<br>
--- a/include/lttng/lttng-error.h<br>
+++ b/include/lttng/lttng-error.h<br>
@@ -134,6 +134,8 @@ enum lttng_error_code {<br>
        LTTNG_ERR_EXCLUSION_NOMEM        = 111, /* Lack of memory while processing event exclusions */<br>
        LTTNG_ERR_INVALID_EVENT_NAME     = 112, /* Invalid event name */<br>
        LTTNG_ERR_INVALID_CHANNEL_NAME   = 113, /* Invalid channel name */<br>
+       LTTNG_ERR_PID_TRACKED            = 114, /* PID already tracked */<br>
+       LTTNG_ERR_PID_NOT_TRACKED        = 115, /* PID not tracked */<br>
<br>
        /* MUST be last element */<br>
        LTTNG_ERR_NR,                           /* Last element */<br>
diff --git a/src/bin/lttng-sessiond/trace-ust.c b/src/bin/lttng-sessiond/trace-ust.c<br>
index 2486696..3881084 100644<br>
--- a/src/bin/lttng-sessiond/trace-ust.c<br>
+++ b/src/bin/lttng-sessiond/trace-ust.c<br>
@@ -656,7 +656,7 @@ int pid_tracker_add_pid(struct ust_pid_tracker *pid_tracker, int pid)<br>
        tracker_node = pid_tracker_lookup(pid_tracker, pid, &iter);<br>
        if (tracker_node) {<br>
                /* Already exists. */<br>
-               retval = LTTNG_ERR_INVALID;<br>
+               retval = LTTNG_ERR_PID_TRACKED;<br>
                goto end;<br>
        }<br>
        tracker_node = zmalloc(sizeof(*tracker_node));<br>
@@ -684,7 +684,7 @@ int pid_tracker_del_pid(struct ust_pid_tracker *pid_tracker, int pid)<br>
        tracker_node = pid_tracker_lookup(pid_tracker, pid, &iter);<br>
        if (!tracker_node) {<br>
                /* Not found */<br>
-               retval = LTTNG_ERR_INVALID;<br>
+               retval = LTTNG_ERR_PID_NOT_TRACKED;<br>
                goto end;<br>
        }<br>
        ret = lttng_ht_del(pid_tracker->ht, &iter);<br>
diff --git a/src/bin/lttng/commands/track-untrack.c b/src/bin/lttng/commands/track-untrack.c<br>
index 9ce8504..b3139c6 100644<br>
--- a/src/bin/lttng/commands/track-untrack.c<br>
+++ b/src/bin/lttng/commands/track-untrack.c<br>
@@ -261,9 +261,28 @@ enum cmd_error_code track_untrack_pid(enum cmd_type cmd_type, const char *cmd_st<br>
                DBG("%s PID %d", cmd_str, pid_list[i]);<br>
                ret = lib_func(handle, pid_list[i]);<br>
                if (ret) {<br>
-                       success = 0;<br>
-                       retval = CMD_ERROR;<br>
+                       switch (-ret) {<br>
+                       case LTTNG_ERR_PID_TRACKED:<br>
+                               WARN("PID %i already tracked in session %s",<br>
+                                               pid_list[i], session_name);<br>
+                               success = 1;<br>
+                               retval = CMD_SUCCESS;<br>
+                               break;<br>
+                       case LTTNG_ERR_PID_NOT_TRACKED:<br>
+                               WARN("PID %i not tracked in session %s",<br>
+                                               pid_list[i], session_name);<br>
+                               success = 1;<br>
+                               retval = CMD_SUCCESS;<br></blockquote><div><br></div><div>I'm wondering if untracking a PID that was not being tracked should be reported as an error... Thoughts anyone?</div><div><br></div><div>Jérémie</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+                               break;<br>
+                       default:<br>
+                               ERR("%s", lttng_strerror(ret));<br>
+                               success = 0;<br>
+                               retval = CMD_ERROR;<br>
+                               break;<br>
+                       }<br>
                } else {<br>
+                       MSG("PID %i %sed in session %s",<br>
+                                       pid_list[i], cmd_str, session_name);<br>
                        success = 1;<br>
                }<br>
<br>
diff --git a/src/common/error.c b/src/common/error.c<br>
index d3e3b94..ad0ac51 100644<br>
--- a/src/common/error.c<br>
+++ b/src/common/error.c<br>
@@ -167,6 +167,8 @@ static const char *error_string_array[] = {<br>
        [ ERROR_INDEX(LTTNG_ERR_MI_NOT_IMPLEMENTED) ] = "Mi feature not implemented",<br>
        [ ERROR_INDEX(LTTNG_ERR_INVALID_EVENT_NAME) ] = "Invalid event name",<br>
        [ ERROR_INDEX(LTTNG_ERR_INVALID_CHANNEL_NAME) ] = "Invalid channel name",<br>
+       [ ERROR_INDEX(LTTNG_ERR_PID_TRACKED) ] = "PID already tracked",<br>
+       [ ERROR_INDEX(LTTNG_ERR_PID_NOT_TRACKED) ] = "PID not tracked",<br>
<br>
        /* Last element */<br>
        [ ERROR_INDEX(LTTNG_ERR_NR) ] = "Unknown error code"<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.9.1<br>
<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Jérémie Galarneau<br>EfficiOS Inc.<br><a href="http://www.efficios.com" target="_blank">http://www.efficios.com</a></div>
</div></div>