2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <sys/types.h>
27 #include <common/mi-lttng.h>
29 #include "../command.h"
32 #ifdef LTTNG_EMBED_HELP
33 static const char help_msg
[] =
34 #include <lttng-version.1.h>
43 static const char *lttng_license
= "lttng is free software and under the GPL license and part LGPL";
45 static struct poptOption long_options
[] = {
46 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
47 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
48 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
55 static void create_version(struct mi_lttng_version
*version
)
57 strncpy(version
->version
, VERSION
, NAME_MAX
);
58 version
->version_major
= VERSION_MAJOR
;
59 version
->version_minor
= VERSION_MINOR
;
60 version
->version_patchlevel
= VERSION_PATCHLEVEL
;
61 strncpy(version
->version_commit
, GIT_VERSION
, NAME_MAX
);
62 strncpy(version
->version_name
, VERSION_NAME
, NAME_MAX
);
63 strncpy(version
->package_url
, PACKAGE_URL
, NAME_MAX
);
67 * Print the machine interface output of this command.
71 int ret
= CMD_SUCCESS
;
72 struct mi_writer
*writer
= NULL
;
73 struct mi_lttng_version version
;
75 create_version(&version
);
77 writer
= mi_lttng_writer_create(fileno(stdout
), lttng_opt_mi
);
79 ret
= -LTTNG_ERR_NOMEM
;
83 /* Open the command element */
84 ret
= mi_lttng_writer_command_open(writer
,
85 mi_lttng_element_command_version
);
91 /* Beginning of output */
92 ret
= mi_lttng_writer_open_element(writer
,
93 mi_lttng_element_command_output
);
99 /* Print the machine interface of version */
100 ret
= mi_lttng_version(writer
, &version
,
101 VERSION_DESCRIPTION
, lttng_license
);
107 /* Close the output element */
108 ret
= mi_lttng_writer_close_element(writer
);
114 /* Close the command */
115 ret
= mi_lttng_writer_command_close(writer
);
122 if (writer
&& mi_lttng_writer_destroy(writer
)) {
123 /* Preserve original error code */
124 ret
= ret
? ret
: -LTTNG_ERR_MI_IO_FAIL
;
134 int cmd_version(int argc
, const char **argv
)
136 int opt
, ret
= CMD_SUCCESS
;
137 static poptContext pc
;
139 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
140 poptReadDefaultConfig(pc
, 0);
142 while ((opt
= poptGetNextOpt(pc
)) != -1) {
147 case OPT_LIST_OPTIONS
:
148 list_cmd_options(stdout
, long_options
);
159 MSG("lttng version " VERSION
" - " VERSION_NAME
"%s",
160 GIT_VERSION
[0] == '\0' ? "" : " - " GIT_VERSION
);
161 MSG("\n" VERSION_DESCRIPTION
"\n");
162 MSG("Web site: https://lttng.org");
163 MSG("\n%s", lttng_license
);