From: David Goulet Date: Sat, 16 Jul 2011 19:51:11 +0000 (-0400) Subject: Add version command X-Git-Tag: v2.0-pre1~29 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=eb9cb8b758bc88e9117fd0726646a7c9ae4f7984 Add version command Signed-off-by: David Goulet --- diff --git a/lttng/Makefile.am b/lttng/Makefile.am index 6aefbae31..45c1e8885 100644 --- a/lttng/Makefile.am +++ b/lttng/Makefile.am @@ -7,7 +7,8 @@ lttng_SOURCES = conf.c commands/start.c commands/add_channel.c \ commands/stop.c commands/enable_events.c \ commands/disable_events.c commands/enable_channels.c \ commands/disable_channels.c commands/add_context.c \ - commands/set_session.c utils.c lttng.c + commands/set_session.c commands/version.c \ + utils.c lttng.c lttng_LDADD = \ $(top_builddir)/liblttngctl/liblttngctl.la diff --git a/lttng/cmd.h b/lttng/cmd.h index e882be245..c81eb5f6a 100644 --- a/lttng/cmd.h +++ b/lttng/cmd.h @@ -49,5 +49,6 @@ extern int cmd_enable_channels(int argc, const char **argv); extern int cmd_disable_channels(int argc, const char **argv); extern int cmd_add_context(int argc, const char **argv); extern int cmd_set_session(int argc, const char **argv); +extern int cmd_version(int argc, const char **argv); #endif /* _LTTNG_CMD_H */ diff --git a/lttng/commands/version.c b/lttng/commands/version.c new file mode 100644 index 000000000..d18afeb2b --- /dev/null +++ b/lttng/commands/version.c @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2011 - David Goulet + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include + +#include "cmd.h" +#include "conf.h" +#include "utils.h" + +enum { + OPT_HELP = 1, +}; + +static struct poptOption long_options[] = { + /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ + {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0}, + {0, 0, 0, 0, 0, 0, 0} +}; + +/* + * usage + */ +static void usage(FILE *ofp) +{ + fprintf(ofp, "usage: lttng version\n"); + fprintf(ofp, "\n"); + fprintf(ofp, " -h, --help Show this help\n"); + fprintf(ofp, "\n"); +} + +/* + * cmd_version + */ +int cmd_version(int argc, const char **argv) +{ + int opt, ret = CMD_SUCCESS; + static poptContext pc; + + pc = poptGetContext(NULL, argc, argv, long_options, 0); + poptReadDefaultConfig(pc, 0); + + while ((opt = poptGetNextOpt(pc)) != -1) { + switch (opt) { + case OPT_HELP: + usage(stderr); + ret = CMD_SUCCESS; + goto end; + default: + usage(stderr); + ret = CMD_UNDEFINED; + goto end; + } + } + + MSG("lttng version " VERSION); + MSG("Web site: http://lttng.org/"); + MSG("\nlttng is free software and under the GPL license."); + +end: + return ret; +} diff --git a/lttng/lttng.c b/lttng/lttng.c index e6e657cc1..7c0abfaf2 100644 --- a/lttng/lttng.c +++ b/lttng/lttng.c @@ -72,6 +72,7 @@ static struct cmd_struct commands[] = { { "disable-channel", cmd_disable_channels}, { "add-context", cmd_add_context}, { "set-session", cmd_set_session}, + { "version", cmd_version}, { NULL, NULL} /* Array closure */ };