Network streaming support
[lttng-tools.git] / src / bin / lttng / commands / disable_consumer.c
diff --git a/src/bin/lttng/commands/disable_consumer.c b/src/bin/lttng/commands/disable_consumer.c
new file mode 100644 (file)
index 0000000..58361db
--- /dev/null
@@ -0,0 +1,165 @@
+/*
+ * Copyright (C) 2012 - David Goulet <dgoulet@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License, version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * 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., 51
+ * Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 <time.h>
+#include <unistd.h>
+
+#include "../command.h"
+#include "../utils.h"
+
+#include <common/defaults.h>
+#include <common/sessiond-comm/sessiond-comm.h>
+#include <common/uri.h>
+
+static int opt_kernel;
+static int opt_userspace;
+static char *opt_session_name;
+
+static struct lttng_handle *handle;
+
+enum {
+       OPT_HELP = 1,
+       OPT_LIST_OPTIONS,
+};
+
+static struct poptOption long_options[] = {
+       /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
+       {"help",           'h', POPT_ARG_NONE, NULL, OPT_HELP, NULL, NULL},
+       {"list-options",     0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
+       {"session",        's', POPT_ARG_STRING, &opt_session_name, 0, 0, 0},
+       {"kernel",         'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
+       {"userspace",      'u', POPT_ARG_VAL, &opt_userspace, 1, 0, 0},
+       {0, 0, 0, 0, 0, 0, 0}
+};
+
+/*
+ * usage
+ */
+static void usage(FILE *ofp)
+{
+       fprintf(ofp, "usage: lttng disable-consumer [-u|-k] [OPTIONS]\n");
+       fprintf(ofp, "\n");
+       fprintf(ofp, "Disable the consumer for a tracing session. This call can\n");
+       fprintf(ofp, "be done BEFORE tracing has started.\n");
+       fprintf(ofp, "\n");
+       fprintf(ofp, "Options:\n");
+       fprintf(ofp, "  -h, --help           Show this help\n");
+       fprintf(ofp, "      --list-options   Simple listing of options\n");
+       fprintf(ofp, "  -s, --session=NAME   Apply to session name\n");
+       fprintf(ofp, "  -k, --kernel         Apply to the kernel tracer\n");
+       fprintf(ofp, "  -u, --userspace      Apply to the user-space tracer\n");
+       fprintf(ofp, "\n");
+}
+
+/*
+ * Disable consumer command.
+ */
+static int disable_consumer(char *session_name)
+{
+       int ret = CMD_SUCCESS;
+       struct lttng_domain dom;
+
+       memset(&dom, 0, sizeof(dom));
+
+       /* Create lttng domain */
+       if (opt_kernel) {
+               dom.type = LTTNG_DOMAIN_KERNEL;
+       } else if (opt_userspace) {
+               dom.type = LTTNG_DOMAIN_UST;
+       } else {
+               ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
+               ret = CMD_ERROR;
+               goto error;
+       }
+
+       handle = lttng_create_handle(session_name, &dom);
+       if (handle == NULL) {
+               ret = -1;
+               goto error;
+       }
+
+       ret = lttng_disable_consumer(handle);
+       if (ret < 0) {
+               ERR("Disabling consumer for session %s: %s", session_name,
+                               lttng_strerror(ret));
+               goto error;
+       }
+
+       MSG("Consumer disabled successfully");
+
+error:
+       lttng_destroy_handle(handle);
+       return ret;
+}
+
+/*
+ * The 'disable-consumer <options>' first level command
+ *
+ * Returns one of the CMD_* result constants.
+ */
+int cmd_disable_consumer(int argc, const char **argv)
+{
+       int opt, ret = CMD_SUCCESS;
+       static poptContext pc;
+       char *session_name = NULL;
+
+       pc = poptGetContext(NULL, argc, argv, long_options, 0);
+       poptReadDefaultConfig(pc, 0);
+
+       while ((opt = poptGetNextOpt(pc)) != -1) {
+               switch (opt) {
+               case OPT_HELP:
+                       usage(stdout);
+                       goto end;
+               case OPT_LIST_OPTIONS:
+                       list_cmd_options(stdout, long_options);
+                       goto end;
+               default:
+                       usage(stderr);
+                       ret = CMD_UNDEFINED;
+                       goto end;
+               }
+       }
+
+       /* Get session name */
+       if (!opt_session_name) {
+               session_name = get_session_name();
+               if (session_name == NULL) {
+                       ret = CMD_ERROR;
+                       goto end;
+               }
+       } else {
+               session_name = opt_session_name;
+       }
+
+       ret = disable_consumer(session_name);
+
+end:
+       if (opt_session_name == NULL) {
+               free(session_name);
+       }
+
+       poptFreeContext(pc);
+       return ret;
+}
This page took 0.02484 seconds and 4 git commands to generate.