Network streaming support
[lttng-tools.git] / src / bin / lttng / commands / disable_consumer.c
1 /*
2 * Copyright (C) 2012 - David Goulet <dgoulet@efficios.com>
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License, version 2 only, as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18 #define _GNU_SOURCE
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 <time.h>
26 #include <unistd.h>
27
28 #include "../command.h"
29 #include "../utils.h"
30
31 #include <common/defaults.h>
32 #include <common/sessiond-comm/sessiond-comm.h>
33 #include <common/uri.h>
34
35 static int opt_kernel;
36 static int opt_userspace;
37 static char *opt_session_name;
38
39 static struct lttng_handle *handle;
40
41 enum {
42 OPT_HELP = 1,
43 OPT_LIST_OPTIONS,
44 };
45
46 static struct poptOption long_options[] = {
47 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
48 {"help", 'h', POPT_ARG_NONE, NULL, OPT_HELP, NULL, NULL},
49 {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
50 {"session", 's', POPT_ARG_STRING, &opt_session_name, 0, 0, 0},
51 {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
52 {"userspace", 'u', POPT_ARG_VAL, &opt_userspace, 1, 0, 0},
53 {0, 0, 0, 0, 0, 0, 0}
54 };
55
56 /*
57 * usage
58 */
59 static void usage(FILE *ofp)
60 {
61 fprintf(ofp, "usage: lttng disable-consumer [-u|-k] [OPTIONS]\n");
62 fprintf(ofp, "\n");
63 fprintf(ofp, "Disable the consumer for a tracing session. This call can\n");
64 fprintf(ofp, "be done BEFORE tracing has started.\n");
65 fprintf(ofp, "\n");
66 fprintf(ofp, "Options:\n");
67 fprintf(ofp, " -h, --help Show this help\n");
68 fprintf(ofp, " --list-options Simple listing of options\n");
69 fprintf(ofp, " -s, --session=NAME Apply to session name\n");
70 fprintf(ofp, " -k, --kernel Apply to the kernel tracer\n");
71 fprintf(ofp, " -u, --userspace Apply to the user-space tracer\n");
72 fprintf(ofp, "\n");
73 }
74
75 /*
76 * Disable consumer command.
77 */
78 static int disable_consumer(char *session_name)
79 {
80 int ret = CMD_SUCCESS;
81 struct lttng_domain dom;
82
83 memset(&dom, 0, sizeof(dom));
84
85 /* Create lttng domain */
86 if (opt_kernel) {
87 dom.type = LTTNG_DOMAIN_KERNEL;
88 } else if (opt_userspace) {
89 dom.type = LTTNG_DOMAIN_UST;
90 } else {
91 ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
92 ret = CMD_ERROR;
93 goto error;
94 }
95
96 handle = lttng_create_handle(session_name, &dom);
97 if (handle == NULL) {
98 ret = -1;
99 goto error;
100 }
101
102 ret = lttng_disable_consumer(handle);
103 if (ret < 0) {
104 ERR("Disabling consumer for session %s: %s", session_name,
105 lttng_strerror(ret));
106 goto error;
107 }
108
109 MSG("Consumer disabled successfully");
110
111 error:
112 lttng_destroy_handle(handle);
113 return ret;
114 }
115
116 /*
117 * The 'disable-consumer <options>' first level command
118 *
119 * Returns one of the CMD_* result constants.
120 */
121 int cmd_disable_consumer(int argc, const char **argv)
122 {
123 int opt, ret = CMD_SUCCESS;
124 static poptContext pc;
125 char *session_name = NULL;
126
127 pc = poptGetContext(NULL, argc, argv, long_options, 0);
128 poptReadDefaultConfig(pc, 0);
129
130 while ((opt = poptGetNextOpt(pc)) != -1) {
131 switch (opt) {
132 case OPT_HELP:
133 usage(stdout);
134 goto end;
135 case OPT_LIST_OPTIONS:
136 list_cmd_options(stdout, long_options);
137 goto end;
138 default:
139 usage(stderr);
140 ret = CMD_UNDEFINED;
141 goto end;
142 }
143 }
144
145 /* Get session name */
146 if (!opt_session_name) {
147 session_name = get_session_name();
148 if (session_name == NULL) {
149 ret = CMD_ERROR;
150 goto end;
151 }
152 } else {
153 session_name = opt_session_name;
154 }
155
156 ret = disable_consumer(session_name);
157
158 end:
159 if (opt_session_name == NULL) {
160 free(session_name);
161 }
162
163 poptFreeContext(pc);
164 return ret;
165 }
This page took 0.032391 seconds and 4 git commands to generate.