Mi stop command: support and validation
authorJonathan Rajotte Julien <jonathan.rajotte-julien@ericsson.com>
Thu, 5 Jun 2014 19:50:40 +0000 (15:50 -0400)
committerJonathan Rajotte Julien <jonathan.r.julien@gmail.com>
Tue, 22 Jul 2014 20:14:56 +0000 (16:14 -0400)
Signed-off-by: Jonathan Rajotte Julien <jonathan.r.julien@gmail.com>
src/bin/lttng/commands/stop.c
src/common/mi-lttng.c
src/common/mi-lttng.h
src/common/mi_lttng.xsd

index 965ab94feb66f45ca5d89752a3da5661f341d415..a72f313dfccb11270607e1c2f9b9985419e820da 100644 (file)
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
-
-#include "../command.h"
+#include <assert.h>
 
 #include <common/sessiond-comm/sessiond-comm.h>
+#include <common/mi-lttng.h>
+
+#include "../command.h"
 
 static char *opt_session_name;
 static int opt_no_wait;
+static struct mi_writer *writer;
 
 enum {
        OPT_HELP = 1,
@@ -60,6 +63,41 @@ static void usage(FILE *ofp)
        fprintf(ofp, "  -n, --no-wait            Don't wait for data availability\n");
        fprintf(ofp, "\n");
 }
+/*
+ * Mi print of partial session
+ */
+static int mi_print_session(char *session_name, int enabled)
+{
+       int ret;
+       assert(writer);
+       assert(session_name);
+
+       /* Open session element */
+       ret = mi_lttng_writer_open_element(writer, config_element_session);
+       if (ret) {
+               goto end;
+       }
+
+       /* Print session name element */
+       ret = mi_lttng_writer_write_element_string(writer, config_element_name,
+                       session_name);
+       if (ret) {
+               goto end;
+       }
+
+       /* Is enabled ? */
+       ret = mi_lttng_writer_write_element_bool(writer, config_element_enabled,
+                       enabled);
+       if (ret) {
+               goto end;
+       }
+
+       /* Close session element */
+       ret = mi_lttng_writer_close_element(writer);
+
+end:
+       return ret;
+}
 
 /*
  * Start tracing for all trace of the session.
@@ -99,7 +137,7 @@ static int stop_tracing(void)
                        ret = lttng_data_pending(session_name);
                        if (ret < 0) {
                                /* Return the data available call error. */
-                               goto error;
+                               goto free_name;
                        }
 
                        /*
@@ -118,6 +156,12 @@ static int stop_tracing(void)
        ret = CMD_SUCCESS;
 
        MSG("Tracing stopped for session %s", session_name);
+       if (lttng_opt_mi) {
+               ret = mi_print_session(session_name, 0);
+               if (ret) {
+                       goto free_name;
+               }
+       }
 
 free_name:
        if (opt_session_name == NULL) {
@@ -135,19 +179,12 @@ error:
  */
 int cmd_stop(int argc, const char **argv)
 {
-       int opt, ret = CMD_SUCCESS;
+       int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1;
        static poptContext pc;
 
        pc = poptGetContext(NULL, argc, argv, long_options, 0);
        poptReadDefaultConfig(pc, 0);
 
-       /* TODO: mi support */
-       if (lttng_opt_mi) {
-               ret = -LTTNG_ERR_MI_NOT_IMPLEMENTED;
-               ERR("mi option not supported");
-               goto end;
-       }
-
        while ((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
                case OPT_HELP:
@@ -163,11 +200,84 @@ int cmd_stop(int argc, const char **argv)
                }
        }
 
+       /* Mi check */
+       if (lttng_opt_mi) {
+               writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi);
+               if (!writer) {
+                       ret = -LTTNG_ERR_NOMEM;
+                       goto end;
+               }
+
+               /* Open command element */
+               ret = mi_lttng_writer_command_open(writer,
+                               mi_lttng_element_command_stop);
+               if (ret) {
+                       ret = CMD_ERROR;
+                       goto end;
+               }
+
+               /* Open output element */
+               ret = mi_lttng_writer_open_element(writer,
+                               mi_lttng_element_command_output);
+               if (ret) {
+                       ret = CMD_ERROR;
+                       goto end;
+               }
+
+               /*
+                * Open sessions element
+                * For validation
+                */
+               ret = mi_lttng_writer_open_element(writer,
+                               config_element_sessions);
+               if (ret) {
+                       ret = CMD_ERROR;
+                       goto end;
+               }
+       }
+
        opt_session_name = (char*) poptGetArg(pc);
 
-       ret = stop_tracing();
+       command_ret = stop_tracing();
+       if (command_ret) {
+               success = 0;
+       }
+
+       /* Mi closing */
+       if (lttng_opt_mi) {
+               /* Close sessions and  output element */
+               ret = mi_lttng_close_multi_element(writer, 2);
+               if (ret) {
+                       ret = CMD_ERROR;
+                       goto end;
+               }
+
+               /* Success ? */
+               ret = mi_lttng_writer_write_element_bool(writer,
+                               mi_lttng_element_command_success, success);
+               if (ret) {
+                       ret = CMD_ERROR;
+                       goto end;
+               }
+
+               /* Command element close */
+               ret = mi_lttng_writer_command_close(writer);
+               if (ret) {
+                       ret = CMD_ERROR;
+                       goto end;
+               }
+       }
 
 end:
+       /* Mi clean-up */
+       if (writer && mi_lttng_writer_destroy(writer)) {
+               /* Preserve original error code */
+               ret = ret ? ret : -LTTNG_ERR_MI_IO_FAIL;
+       }
+
+       /* Overwrite ret if an error occurred in stop_tracing() */
+       ret = command_ret ? command_ret : ret;
+
        poptFreeContext(pc);
        return ret;
 }
index 453be4f28f387881b2856a2ffb715afab8f3ddf8..e7f08117766c738b9f07ad2b307c1d03c5e12283 100644 (file)
@@ -31,6 +31,7 @@ const char * const mi_lttng_element_command_save = "save";
 const char * const mi_lttng_element_command_load = "load";
 const char * const mi_lttng_element_command_name = "name";
 const char * const mi_lttng_element_command_start = "start";
+const char * const mi_lttng_element_command_stop = "stop";
 const char * const mi_lttng_element_command_output = "output";
 const char * const mi_lttng_element_command_success = "success";
 
index 7be4a29b9a208e100f0bc1df788887e7f336a793..6151118ca63ebec5020b446d2b2b240985166857 100644 (file)
@@ -51,6 +51,7 @@ const char * const mi_lttng_element_command_version;
 const char * const mi_lttng_element_command_list;
 const char * const mi_lttng_element_command_save;
 const char * const mi_lttng_element_command_load;
+const char * const mi_lttng_element_command_stop;
 const char * const mi_lttng_element_command_name;
 const char * const mi_lttng_element_command_start;
 const char * const mi_lttng_element_command_output;
index b0649bff064b4b50aae45032fd9d4612e3a68835..587d735c9553fd252031670f4ad6a24cc560c22f 100644 (file)
@@ -327,6 +327,7 @@ THE SOFTWARE.
                        <xs:enumeration value="save" />
                        <xs:enumeration value="load" />
                        <xs:enumeration value="start" />
+                       <xs:enumeration value="stop" />
                </xs:restriction>
        </xs:simpleType>
 
This page took 0.039099 seconds and 4 git commands to generate.