2 * Copyright (C) 2011 EfficiOS Inc.
4 * SPDX-License-Identifier: GPL-2.0-only
14 #include <sys/types.h>
17 #include <common/mi-lttng.hpp>
19 #include "../command.hpp"
20 #include "version.hpp"
22 #ifdef LTTNG_EMBED_HELP
23 static const char help_msg
[] =
24 #include <lttng-version.1.h>
33 static const char *lttng_license
= "lttng is free software and under the GPL license and part LGPL";
35 static struct poptOption long_options
[] = {
36 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
37 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
38 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
45 static void create_version(struct mi_lttng_version_data
*version
)
47 strncpy(version
->version
, VERSION
, NAME_MAX
);
48 version
->version_major
= VERSION_MAJOR
;
49 version
->version_minor
= VERSION_MINOR
;
50 version
->version_patchlevel
= VERSION_PATCHLEVEL
;
51 strncpy(version
->version_commit
, GIT_VERSION
, NAME_MAX
);
52 strncpy(version
->version_name
, VERSION_NAME
, NAME_MAX
);
53 strncpy(version
->package_url
, PACKAGE_URL
, NAME_MAX
);
57 * Print the machine interface output of this command.
59 static int print_mi(void)
61 int ret
= CMD_SUCCESS
;
62 struct mi_writer
*writer
= NULL
;
63 struct mi_lttng_version_data version
;
65 create_version(&version
);
67 writer
= mi_lttng_writer_create(fileno(stdout
), lttng_opt_mi
);
69 ret
= -LTTNG_ERR_NOMEM
;
73 /* Open the command element */
74 ret
= mi_lttng_writer_command_open(writer
,
75 mi_lttng_element_command_version
);
81 /* Beginning of output */
82 ret
= mi_lttng_writer_open_element(writer
,
83 mi_lttng_element_command_output
);
89 /* Print the machine interface of version */
90 ret
= mi_lttng_version(writer
, &version
,
91 VERSION_DESCRIPTION
, lttng_license
);
97 /* Close the output element */
98 ret
= mi_lttng_writer_close_element(writer
);
104 /* Close the command */
105 ret
= mi_lttng_writer_command_close(writer
);
112 if (writer
&& mi_lttng_writer_destroy(writer
)) {
113 /* Preserve original error code */
114 ret
= ret
? ret
: -LTTNG_ERR_MI_IO_FAIL
;
124 int cmd_version(int argc
, const char **argv
)
126 int opt
, ret
= CMD_SUCCESS
;
127 static poptContext pc
;
129 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
130 poptReadDefaultConfig(pc
, 0);
132 while ((opt
= poptGetNextOpt(pc
)) != -1) {
137 case OPT_LIST_OPTIONS
:
138 list_cmd_options(stdout
, long_options
);
149 MSG("lttng version " VERSION
" - " VERSION_NAME
"%s",
150 GIT_VERSION
[0] == '\0' ? "" : " - " GIT_VERSION
);
151 MSG("\n" VERSION_DESCRIPTION
"\n");
152 MSG("Web site: https://lttng.org");
153 MSG("\n%s", lttng_license
);
154 if (EXTRA_VERSION_NAME
[0] != '\0') {
155 MSG("\nExtra version name: " EXTRA_VERSION_NAME
);
157 if (EXTRA_VERSION_DESCRIPTION
[0] != '\0') {
158 MSG("\nExtra version description:\n\t" EXTRA_VERSION_DESCRIPTION
);
160 if (EXTRA_VERSION_PATCHES
[0] != '\0') {
161 MSG("\nExtra version patches:\n\t" EXTRA_VERSION_PATCHES
);