Add version command
authorDavid Goulet <david.goulet@polymtl.ca>
Sat, 16 Jul 2011 19:51:11 +0000 (15:51 -0400)
committerDavid Goulet <david.goulet@polymtl.ca>
Sat, 16 Jul 2011 19:51:11 +0000 (15:51 -0400)
Signed-off-by: David Goulet <david.goulet@polymtl.ca>
lttng/Makefile.am
lttng/cmd.h
lttng/commands/version.c [new file with mode: 0644]
lttng/lttng.c

index 6aefbae31ba1bf4b5ed0821215e39cd0a021be21..45c1e8885d8b0aa327a310ee08dc73b15da8f037 100644 (file)
@@ -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
index e882be245d7db1ceea1816c41e403c12aa1d1899..c81eb5f6abb4f952e81f5a40447b984385827fa8 100644 (file)
@@ -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 (file)
index 0000000..d18afeb
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ *
+ * 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 <popt.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#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;
+}
index e6e657cc1ec4e59438bd011b55f5345de7894d19..7c0abfaf211fd42ef309f9bf0eaa47e1ff329a61 100644 (file)
@@ -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 */
 };
 
This page took 0.027398 seconds and 4 git commands to generate.