From: Jonathan Rajotte Julien Date: Thu, 5 Jun 2014 14:27:41 +0000 (-0400) Subject: Mi start command: support and validation X-Git-Tag: v2.6.0-rc1~127 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=1cfc0bc8024dbe354bfe6c351cf00188d1f02763;p=lttng-tools.git Mi start command: support and validation Signed-off-by: Jonathan Rajotte Julien --- diff --git a/src/bin/lttng/commands/start.c b/src/bin/lttng/commands/start.c index 82b3f5f86..5ca92d8d1 100644 --- a/src/bin/lttng/commands/start.c +++ b/src/bin/lttng/commands/start.c @@ -24,11 +24,14 @@ #include #include +#include +#include + #include "../command.h" -#include static char *opt_session_name; +static struct mi_writer *writer; enum { OPT_HELP = 1, @@ -58,6 +61,36 @@ static void usage(FILE *ofp) fprintf(ofp, "\n"); } +static int mi_print_session(char *session_name, int enabled) +{ + int ret; + + /* 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; + } + + 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 * @@ -96,6 +129,13 @@ static int start_tracing(void) ret = CMD_SUCCESS; MSG("Tracing started for session %s", session_name); + if (lttng_opt_mi) { + ret = mi_print_session(session_name, 1); + if (ret) { + ret = CMD_ERROR; + goto free_name; + } + } free_name: if (opt_session_name == NULL) { @@ -112,19 +152,12 @@ error: */ int cmd_start(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: @@ -142,9 +175,81 @@ int cmd_start(int argc, const char **argv) opt_session_name = (char*) poptGetArg(pc); - ret = start_tracing(); + /* 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_start); + 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 purpose + */ + ret = mi_lttng_writer_open_element(writer, + config_element_sessions); + if (ret) { + ret = CMD_ERROR; + goto end; + } + } + + command_ret = start_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 with start_tracing */ + ret = command_ret ? command_ret : ret; poptFreeContext(pc); return ret; } diff --git a/src/common/mi-lttng.c b/src/common/mi-lttng.c index 12f7030fa..453be4f28 100644 --- a/src/common/mi-lttng.c +++ b/src/common/mi-lttng.c @@ -30,6 +30,7 @@ const char * const mi_lttng_element_command_list = "list"; 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_output = "output"; const char * const mi_lttng_element_command_success = "success"; diff --git a/src/common/mi-lttng.h b/src/common/mi-lttng.h index a7b3006fa..7be4a29b9 100644 --- a/src/common/mi-lttng.h +++ b/src/common/mi-lttng.h @@ -52,6 +52,7 @@ 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_name; +const char * const mi_lttng_element_command_start; const char * const mi_lttng_element_command_output; const char * const mi_lttng_element_command_success; diff --git a/src/common/mi_lttng.xsd b/src/common/mi_lttng.xsd index 8aca79f40..b0649bff0 100644 --- a/src/common/mi_lttng.xsd +++ b/src/common/mi_lttng.xsd @@ -326,6 +326,7 @@ THE SOFTWARE. +