Introduce EXTRA_VERSION_PATCHES
[lttng-tools.git] / src / bin / lttng / commands / version.c
CommitLineData
eb9cb8b7
DG
1/*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 *
d14d33bf
AM
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.
eb9cb8b7
DG
7 *
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.
12 *
d14d33bf
AM
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.
eb9cb8b7
DG
16 */
17
6c1c0768 18#define _LGPL_SOURCE
eb9cb8b7
DG
19#include <popt.h>
20#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
23#include <sys/stat.h>
24#include <sys/types.h>
25#include <unistd.h>
26
c7e35b03
JR
27#include <common/mi-lttng.h>
28
c399183f 29#include "../command.h"
979d476d 30#include "version.h"
eb9cb8b7 31
4fc83d94
PP
32#ifdef LTTNG_EMBED_HELP
33static const char help_msg[] =
34#include <lttng-version.1.h>
35;
36#endif
37
eb9cb8b7
DG
38enum {
39 OPT_HELP = 1,
679b4943 40 OPT_LIST_OPTIONS,
eb9cb8b7
DG
41};
42
c7e35b03
JR
43static const char *lttng_license = "lttng is free software and under the GPL license and part LGPL";
44
eb9cb8b7
DG
45static struct poptOption long_options[] = {
46 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
47 {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
679b4943 48 {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
eb9cb8b7
DG
49 {0, 0, 0, 0, 0, 0, 0}
50};
51
c7e35b03
JR
52/*
53 * create_version
54 */
55static void create_version(struct mi_lttng_version *version)
56{
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;
50bba0f3 61 strncpy(version->version_commit, GIT_VERSION, NAME_MAX);
c7e35b03
JR
62 strncpy(version->version_name, VERSION_NAME, NAME_MAX);
63 strncpy(version->package_url, PACKAGE_URL, NAME_MAX);
64}
65
66/*
67 * Print the machine interface output of this command.
68 */
69static int print_mi()
70{
71 int ret = CMD_SUCCESS;
72 struct mi_writer *writer = NULL;
73 struct mi_lttng_version version;
74
75 create_version(&version);
76
77 writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi);
78 if (!writer) {
79 ret = -LTTNG_ERR_NOMEM;
80 goto end;
81 }
82
83 /* Open the command element */
84 ret = mi_lttng_writer_command_open(writer,
85 mi_lttng_element_command_version);
86 if (ret) {
87 ret = CMD_ERROR;
88 goto error;
89 }
90
91 /* Beginning of output */
92 ret = mi_lttng_writer_open_element(writer,
93 mi_lttng_element_command_output);
94 if (ret) {
95 ret = CMD_ERROR;
96 goto error;
97 }
98
99 /* Print the machine interface of version */
100 ret = mi_lttng_version(writer, &version,
101 VERSION_DESCRIPTION, lttng_license);
102 if (ret) {
103 ret = CMD_ERROR;
104 goto error;
105 }
106
107 /* Close the output element */
108 ret = mi_lttng_writer_close_element(writer);
109 if (ret) {
110 ret = CMD_ERROR;
111 goto error;
112 }
113
114 /* Close the command */
115 ret = mi_lttng_writer_command_close(writer);
116 if (ret) {
117 ret = CMD_ERROR;
118 }
119
120error:
121 /* Cleanup */
122 if (writer && mi_lttng_writer_destroy(writer)) {
123 /* Preserve original error code */
124 ret = ret ? ret : -LTTNG_ERR_MI_IO_FAIL;
125 }
126
127end:
128 return ret;
129}
130
eb9cb8b7
DG
131/*
132 * cmd_version
133 */
134int cmd_version(int argc, const char **argv)
135{
136 int opt, ret = CMD_SUCCESS;
137 static poptContext pc;
138
139 pc = poptGetContext(NULL, argc, argv, long_options, 0);
140 poptReadDefaultConfig(pc, 0);
141
142 while ((opt = poptGetNextOpt(pc)) != -1) {
143 switch (opt) {
144 case OPT_HELP:
4ba92f18 145 SHOW_HELP();
eb9cb8b7 146 goto end;
679b4943
SM
147 case OPT_LIST_OPTIONS:
148 list_cmd_options(stdout, long_options);
679b4943 149 goto end;
eb9cb8b7 150 default:
eb9cb8b7
DG
151 ret = CMD_UNDEFINED;
152 goto end;
153 }
154 }
155
c7e35b03
JR
156 if (lttng_opt_mi) {
157 ret = print_mi();
158 } else {
4c6ac053
MD
159 MSG("lttng version " VERSION " - " VERSION_NAME "%s",
160 GIT_VERSION[0] == '\0' ? "" : " - " GIT_VERSION);
c7e35b03 161 MSG("\n" VERSION_DESCRIPTION "\n");
a18d9544 162 MSG("Web site: https://lttng.org");
c7e35b03 163 MSG("\n%s", lttng_license);
a3bc3918
JR
164 if (EXTRA_VERSION_NAME[0] != '\0') {
165 MSG("\nExtra version name: " EXTRA_VERSION_NAME);
166 }
167 if (EXTRA_VERSION_DESCRIPTION[0] != '\0') {
168 MSG("\nExtra version description:\n\t" EXTRA_VERSION_DESCRIPTION);
169 }
7f5ed73a
JR
170 if (EXTRA_VERSION_PATCHES[0] != '\0') {
171 MSG("\nExtra version patches:\n\t" EXTRA_VERSION_PATCHES);
172 }
c7e35b03 173 }
eb9cb8b7
DG
174
175end:
ca1c3607 176 poptFreeContext(pc);
eb9cb8b7
DG
177 return ret;
178}
This page took 0.115951 seconds and 5 git commands to generate.