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 usage(FILE *ofp
)
50 fprintf(ofp
, "usage: lttng version [OPTIONS]\n");
52 fprintf(ofp
, "Options:\n");
53 fprintf(ofp
, " -h, --help Show this help\n");
54 fprintf(ofp
, " --list-options Simple listing of options\n");
61 static void create_version(struct mi_lttng_version
*version
)
63 strncpy(version
->version
, VERSION
, NAME_MAX
);
64 version
->version_major
= VERSION_MAJOR
;
65 version
->version_minor
= VERSION_MINOR
;
66 version
->version_patchlevel
= VERSION_PATCHLEVEL
;
67 strncpy(version
->version_commit
, GIT_VERSION
, NAME_MAX
);
68 strncpy(version
->version_name
, VERSION_NAME
, NAME_MAX
);
69 strncpy(version
->package_url
, PACKAGE_URL
, NAME_MAX
);
73 * Print the machine interface output of this command.
77 int ret
= CMD_SUCCESS
;
78 struct mi_writer
*writer
= NULL
;
79 struct mi_lttng_version version
;
81 create_version(&version
);
83 writer
= mi_lttng_writer_create(fileno(stdout
), lttng_opt_mi
);
85 ret
= -LTTNG_ERR_NOMEM
;
89 /* Open the command element */
90 ret
= mi_lttng_writer_command_open(writer
,
91 mi_lttng_element_command_version
);
97 /* Beginning of output */
98 ret
= mi_lttng_writer_open_element(writer
,
99 mi_lttng_element_command_output
);
105 /* Print the machine interface of version */
106 ret
= mi_lttng_version(writer
, &version
,
107 VERSION_DESCRIPTION
, lttng_license
);
113 /* Close the output element */
114 ret
= mi_lttng_writer_close_element(writer
);
120 /* Close the command */
121 ret
= mi_lttng_writer_command_close(writer
);
128 if (writer
&& mi_lttng_writer_destroy(writer
)) {
129 /* Preserve original error code */
130 ret
= ret
? ret
: -LTTNG_ERR_MI_IO_FAIL
;
140 int cmd_version(int argc
, const char **argv
)
142 int opt
, ret
= CMD_SUCCESS
;
143 static poptContext pc
;
145 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
146 poptReadDefaultConfig(pc
, 0);
148 while ((opt
= poptGetNextOpt(pc
)) != -1) {
153 case OPT_LIST_OPTIONS
:
154 list_cmd_options(stdout
, long_options
);
166 MSG("lttng version " VERSION
" - " VERSION_NAME
"%s",
167 GIT_VERSION
[0] == '\0' ? "" : " - " GIT_VERSION
);
168 MSG("\n" VERSION_DESCRIPTION
"\n");
169 MSG("Web site: http://lttng.org");
170 MSG("\n%s", lttng_license
);