Add set session command to lttng cli
authorDavid Goulet <david.goulet@polymtl.ca>
Thu, 30 Jun 2011 21:20:06 +0000 (17:20 -0400)
committerDavid Goulet <david.goulet@polymtl.ca>
Thu, 30 Jun 2011 21:20:06 +0000 (17:20 -0400)
This command change the session name in the config file of the config
directory (.lttng).

Signed-off-by: David Goulet <david.goulet@polymtl.ca>
lttng/Makefile.am
lttng/cmd.h
lttng/commands/set_session.c [new file with mode: 0644]
lttng/lttng.c

index 159d81728e1dfe2c59d8e47d6742441ec3b4809d..6aefbae31ba1bf4b5ed0821215e39cd0a021be21 100644 (file)
@@ -7,7 +7,7 @@ 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 \
-                               utils.c lttng.c
+                               commands/set_session.c utils.c lttng.c
 
 lttng_LDADD = \
                $(top_builddir)/liblttngctl/liblttngctl.la
index a59a7f5aae337ec9cc2c96ba61a21ef1b8577fe0..e882be245d7db1ceea1816c41e403c12aa1d1899 100644 (file)
@@ -48,5 +48,6 @@ extern int cmd_disable_events(int argc, const char **argv);
 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);
 
 #endif /* _LTTNG_CMD_H */
diff --git a/lttng/commands/set_session.c b/lttng/commands/set_session.c
new file mode 100644 (file)
index 0000000..f89545f
--- /dev/null
@@ -0,0 +1,133 @@
+/*
+ * 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"
+
+static char *opt_session_name;
+
+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 set-session NAME\n");
+       fprintf(ofp, "\n");
+       fprintf(ofp, "Options:\n");
+       fprintf(ofp, "  -h, --help               Show this help\n");
+       fprintf(ofp, "\n");
+}
+
+/*
+ *  set_session
+ */
+static int set_session(void)
+{
+       int ret = CMD_SUCCESS;
+       char *path, *alloc_path;
+
+       alloc_path = config_get_default_path();
+       if (alloc_path == NULL) {
+               ERR("Unable to find config directory");
+               ret = CMD_ERROR;
+               goto error;
+       }
+
+       path = config_generate_dir_path(alloc_path);
+       if (path == NULL) {
+               ret = CMD_FATAL;
+               goto error;
+       }
+
+       ret = config_init(path);
+       if (ret < 0) {
+               ERR("Init config directory and file failed");
+               ret = CMD_ERROR;
+               goto error;
+       }
+
+       ret = config_add_session_name(path, opt_session_name);
+       if (ret < 0) {
+               ERR("Unable to add session name to config");
+               ret = CMD_ERROR;
+               goto error;
+       }
+
+       MSG("Session set to %s", opt_session_name);
+       ret = CMD_SUCCESS;
+
+error:
+       return ret;
+}
+
+/*
+ *  cmd_set_session
+ */
+int cmd_set_session(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;
+               }
+       }
+
+       opt_session_name = (char *) poptGetArg(pc);
+       if (opt_session_name == NULL) {
+               ERR("Missing session name");
+               usage(stderr);
+               goto end;
+       }
+
+       ret = set_session();
+
+end:
+       return ret;
+}
index d32f563dd1ea6cab7deaa82520f01da41a982721..e1b52c84811217714425f54ccdb2078ab4f57085 100644 (file)
@@ -67,6 +67,7 @@ static struct cmd_struct commands[] =  {
        { "enable-channel", cmd_enable_channels},
        { "disable-channel", cmd_disable_channels},
        { "add-context", cmd_add_context},
+       { "set-session", cmd_set_session},
        { NULL, NULL}   /* Array closure */
 };
 
@@ -93,6 +94,7 @@ static void usage(FILE *ofp)
        fprintf(ofp, "    disable-channel Disable tracing channel\n");
        fprintf(ofp, "    disable-event   Disable tracing event\n");
        fprintf(ofp, "    list            List possible tracing options\n");
+       fprintf(ofp, "    set-session     Set current session name\n");
        fprintf(ofp, "    start           Start tracing\n");
        fprintf(ofp, "    stop            Stop tracing\n");
        fprintf(ofp, "    version         Show version information\n");
This page took 0.028414 seconds and 4 git commands to generate.