X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Fversion.c;h=7634f5871a0eaec92e7a4820e36e21c487905aa1;hp=0b90fa172951efe87d11654b6394a82ce7b86ffc;hb=890d8fe47755c3bad936389cf48ffa141cff41c9;hpb=9afbd878f072d5e0577811acf1d3340f65cf2e26 diff --git a/src/bin/lttng/commands/version.c b/src/bin/lttng/commands/version.c index 0b90fa172..7634f5871 100644 --- a/src/bin/lttng/commands/version.c +++ b/src/bin/lttng/commands/version.c @@ -15,7 +15,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#define _GNU_SOURCE +#define _LGPL_SOURCE #include #include #include @@ -23,7 +23,8 @@ #include #include #include -#include + +#include #include "../command.h" @@ -32,6 +33,8 @@ enum { OPT_LIST_OPTIONS, }; +static const char *lttng_license = "lttng is free software and under the GPL license and part LGPL"; + static struct poptOption long_options[] = { /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0}, @@ -52,6 +55,85 @@ static void usage(FILE *ofp) fprintf(ofp, "\n"); } +/* + * create_version + */ +static void create_version(struct mi_lttng_version *version) +{ + strncpy(version->version, VERSION, NAME_MAX); + version->version_major = VERSION_MAJOR; + version->version_minor = VERSION_MINOR; + version->version_patchlevel = VERSION_PATCHLEVEL; + strncpy(version->version_commit, GIT_VERSION, NAME_MAX); + strncpy(version->version_name, VERSION_NAME, NAME_MAX); + strncpy(version->package_url, PACKAGE_URL, NAME_MAX); +} + +/* + * Print the machine interface output of this command. + */ +static int print_mi() +{ + int ret = CMD_SUCCESS; + struct mi_writer *writer = NULL; + struct mi_lttng_version version; + + create_version(&version); + + writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi); + if (!writer) { + ret = -LTTNG_ERR_NOMEM; + goto end; + } + + /* Open the command element */ + ret = mi_lttng_writer_command_open(writer, + mi_lttng_element_command_version); + if (ret) { + ret = CMD_ERROR; + goto error; + } + + /* Beginning of output */ + ret = mi_lttng_writer_open_element(writer, + mi_lttng_element_command_output); + if (ret) { + ret = CMD_ERROR; + goto error; + } + + /* Print the machine interface of version */ + ret = mi_lttng_version(writer, &version, + VERSION_DESCRIPTION, lttng_license); + if (ret) { + ret = CMD_ERROR; + goto error; + } + + /* Close the output element */ + ret = mi_lttng_writer_close_element(writer); + if (ret) { + ret = CMD_ERROR; + goto error; + } + + /* Close the command */ + ret = mi_lttng_writer_command_close(writer); + if (ret) { + ret = CMD_ERROR; + } + +error: + /* Cleanup */ + if (writer && mi_lttng_writer_destroy(writer)) { + /* Preserve original error code */ + ret = ret ? ret : -LTTNG_ERR_MI_IO_FAIL; + } + +end: + return ret; +} + /* * cmd_version */ @@ -78,10 +160,15 @@ int cmd_version(int argc, const char **argv) } } - MSG("LTTng version " VERSION " - " VERSION_NAME); - MSG("\n" VERSION_DESCRIPTION "\n"); - MSG("Web site: " PACKAGE_URL "\n"); - MSG("LTTng is free software and under the GPL license and part LGPL"); + if (lttng_opt_mi) { + ret = print_mi(); + } else { + MSG("lttng version " VERSION " - " VERSION_NAME "%s", + GIT_VERSION[0] == '\0' ? "" : " - " GIT_VERSION); + MSG("\n" VERSION_DESCRIPTION "\n"); + MSG("Web site: http://lttng.org"); + MSG("\n%s", lttng_license); + } end: poptFreeContext(pc);