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"
36 static const char *lttng_license
= "lttng is free software and under the GPL license and part LGPL";
38 static struct poptOption long_options
[] = {
39 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
40 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
41 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
48 static void create_version(struct mi_lttng_version
*version
)
50 strncpy(version
->version
, VERSION
, NAME_MAX
);
51 version
->version_major
= VERSION_MAJOR
;
52 version
->version_minor
= VERSION_MINOR
;
53 version
->version_patchlevel
= VERSION_PATCHLEVEL
;
54 strncpy(version
->version_commit
, GIT_VERSION
, NAME_MAX
);
55 strncpy(version
->version_name
, VERSION_NAME
, NAME_MAX
);
56 strncpy(version
->package_url
, PACKAGE_URL
, NAME_MAX
);
60 * Print the machine interface output of this command.
64 int ret
= CMD_SUCCESS
;
65 struct mi_writer
*writer
= NULL
;
66 struct mi_lttng_version version
;
68 create_version(&version
);
70 writer
= mi_lttng_writer_create(fileno(stdout
), lttng_opt_mi
);
72 ret
= -LTTNG_ERR_NOMEM
;
76 /* Open the command element */
77 ret
= mi_lttng_writer_command_open(writer
,
78 mi_lttng_element_command_version
);
84 /* Beginning of output */
85 ret
= mi_lttng_writer_open_element(writer
,
86 mi_lttng_element_command_output
);
92 /* Print the machine interface of version */
93 ret
= mi_lttng_version(writer
, &version
,
94 VERSION_DESCRIPTION
, lttng_license
);
100 /* Close the output element */
101 ret
= mi_lttng_writer_close_element(writer
);
107 /* Close the command */
108 ret
= mi_lttng_writer_command_close(writer
);
115 if (writer
&& mi_lttng_writer_destroy(writer
)) {
116 /* Preserve original error code */
117 ret
= ret
? ret
: -LTTNG_ERR_MI_IO_FAIL
;
127 int cmd_version(int argc
, const char **argv
)
129 int opt
, ret
= CMD_SUCCESS
;
130 static poptContext pc
;
132 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
133 poptReadDefaultConfig(pc
, 0);
135 while ((opt
= poptGetNextOpt(pc
)) != -1) {
140 case OPT_LIST_OPTIONS
:
141 list_cmd_options(stdout
, long_options
);
152 MSG("lttng version " VERSION
" - " VERSION_NAME
"%s",
153 GIT_VERSION
[0] == '\0' ? "" : " - " GIT_VERSION
);
154 MSG("\n" VERSION_DESCRIPTION
"\n");
155 MSG("Web site: http://lttng.org");
156 MSG("\n%s", lttng_license
);