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.
25 #include <sys/types.h>
29 #include <common/mi-lttng.h>
31 #include "../command.h"
38 static const char *lttng_license
= "lttng is free software and under the GPL license and part LGPL";
40 static struct poptOption long_options
[] = {
41 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
42 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
43 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
50 static void usage(FILE *ofp
)
52 fprintf(ofp
, "usage: lttng version [OPTIONS]\n");
54 fprintf(ofp
, "Options:\n");
55 fprintf(ofp
, " -h, --help Show this help\n");
56 fprintf(ofp
, " --list-options Simple listing of options\n");
63 static void create_version(struct mi_lttng_version
*version
)
65 strncpy(version
->version
, VERSION
, NAME_MAX
);
66 version
->version_major
= VERSION_MAJOR
;
67 version
->version_minor
= VERSION_MINOR
;
68 version
->version_patchlevel
= VERSION_PATCHLEVEL
;
69 strncpy(version
->version_commit
, GIT_VERSION
, NAME_MAX
);
70 strncpy(version
->version_name
, VERSION_NAME
, NAME_MAX
);
71 strncpy(version
->package_url
, PACKAGE_URL
, NAME_MAX
);
75 * Print the machine interface output of this command.
79 int ret
= CMD_SUCCESS
;
80 struct mi_writer
*writer
= NULL
;
81 struct mi_lttng_version version
;
83 create_version(&version
);
85 writer
= mi_lttng_writer_create(fileno(stdout
), lttng_opt_mi
);
87 ret
= -LTTNG_ERR_NOMEM
;
91 /* Open the command element */
92 ret
= mi_lttng_writer_command_open(writer
,
93 mi_lttng_element_command_version
);
99 /* Beginning of output */
100 ret
= mi_lttng_writer_open_element(writer
,
101 mi_lttng_element_command_output
);
107 /* Print the machine interface of version */
108 ret
= mi_lttng_version(writer
, &version
,
109 VERSION_DESCRIPTION
, lttng_license
);
115 /* Close the output element */
116 ret
= mi_lttng_writer_close_element(writer
);
122 /* Close the command */
123 ret
= mi_lttng_writer_command_close(writer
);
130 if (writer
&& mi_lttng_writer_destroy(writer
)) {
131 /* Preserve original error code */
132 ret
= ret
? ret
: -LTTNG_ERR_MI_IO_FAIL
;
142 int cmd_version(int argc
, const char **argv
)
144 int opt
, ret
= CMD_SUCCESS
;
145 static poptContext pc
;
147 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
148 poptReadDefaultConfig(pc
, 0);
150 while ((opt
= poptGetNextOpt(pc
)) != -1) {
155 case OPT_LIST_OPTIONS
:
156 list_cmd_options(stdout
, long_options
);
168 MSG("lttng version " VERSION
" - " VERSION_NAME
"%s",
169 GIT_VERSION
[0] == '\0' ? "" : " - " GIT_VERSION
);
170 MSG("\n" VERSION_DESCRIPTION
"\n");
171 MSG("Web site: http://lttng.org");
172 MSG("\n%s", lttng_license
);