Initialize all stack variables to zero, fix uninitialized loglevel variables
[lttng-tools.git] / src / bin / lttng / commands / disable_channels.c
CommitLineData
26cc6b4e
DG
1/*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
82a3637f
DG
6 * as published by the Free Software Foundation; only version 2
7 * of the License.
26cc6b4e
DG
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19#define _GNU_SOURCE
20#include <popt.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <sys/stat.h>
25#include <sys/types.h>
26#include <unistd.h>
27
c399183f 28#include "../command.h"
26cc6b4e
DG
29
30static char *opt_channels;
e14f64a8 31static int opt_kernel;
5440dc42 32static char *opt_session_name;
26cc6b4e 33static int opt_userspace;
d78d6610
DG
34#if 0
35/* Not implemented yet */
eeac7d46 36static char *opt_cmd_name;
26cc6b4e 37static pid_t opt_pid;
d78d6610 38#endif
26cc6b4e
DG
39
40enum {
41 OPT_HELP = 1,
42 OPT_USERSPACE,
679b4943 43 OPT_LIST_OPTIONS,
26cc6b4e
DG
44};
45
cd80958d
DG
46static struct lttng_handle *handle;
47
26cc6b4e
DG
48static struct poptOption long_options[] = {
49 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
50 {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
5440dc42 51 {"session", 's', POPT_ARG_STRING, &opt_session_name, 0, 0, 0},
26cc6b4e 52 {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
d78d6610
DG
53#if 0
54 /* Not implemented yet */
6caa2bcc 55 {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_cmd_name, OPT_USERSPACE, 0, 0},
26cc6b4e 56 {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0},
d78d6610
DG
57#else
58 {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0},
59#endif
679b4943 60 {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
26cc6b4e
DG
61 {0, 0, 0, 0, 0, 0, 0}
62};
63
64/*
65 * usage
66 */
67static void usage(FILE *ofp)
68{
69 fprintf(ofp, "usage: lttng disable-channel NAME[,NAME2,...] [options]\n");
70 fprintf(ofp, "\n");
78f0bacd 71 fprintf(ofp, " -h, --help Show this help\n");
679b4943 72 fprintf(ofp, " --list-options Simple listing of options\n");
27221701
DG
73 fprintf(ofp, " -s, --session Apply to session name\n");
74 fprintf(ofp, " -k, --kernel Apply to the kernel tracer\n");
d78d6610 75#if 0
27221701 76 fprintf(ofp, " -u, --userspace [CMD] Apply to the user-space tracer\n");
e14f64a8
DG
77 fprintf(ofp, " If no CMD, the domain used is UST global\n");
78 fprintf(ofp, " or else the domain is UST EXEC_NAME\n");
79 fprintf(ofp, " -p, --pid PID If -u, apply to specific PID (domain: UST PID)\n");
d78d6610 80#else
27221701 81 fprintf(ofp, " -u, --userspace Apply to the user-space tracer\n");
d78d6610 82#endif
26cc6b4e
DG
83 fprintf(ofp, "\n");
84}
85
86/*
cd80958d 87 * Disabling channel using the lttng API.
26cc6b4e 88 */
cd80958d 89static int disable_channels(char *session_name)
26cc6b4e 90{
ae856491 91 int ret = CMD_SUCCESS, warn = 0;
26cc6b4e 92 char *channel_name;
7d29a247 93 struct lttng_domain dom;
26cc6b4e 94
441c16a7
MD
95 memset(&dom, 0, sizeof(dom));
96
d78d6610 97 /* Create lttng domain */
7d29a247
DG
98 if (opt_kernel) {
99 dom.type = LTTNG_DOMAIN_KERNEL;
d78d6610 100 } else if (opt_userspace) {
78f0bacd 101 dom.type = LTTNG_DOMAIN_UST;
78f0bacd 102 } else {
e14f64a8 103 ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
d16c1a4c 104 ret = CMD_ERROR;
78f0bacd 105 goto error;
7d29a247
DG
106 }
107
cd80958d
DG
108 handle = lttng_create_handle(session_name, &dom);
109 if (handle == NULL) {
110 ret = -1;
111 goto error;
112 }
113
26cc6b4e
DG
114 /* Strip channel list */
115 channel_name = strtok(opt_channels, ",");
116 while (channel_name != NULL) {
78f0bacd
DG
117 DBG("Disabling channel %s", channel_name);
118
119 ret = lttng_disable_channel(handle, channel_name);
120 if (ret < 0) {
ae856491
DG
121 ERR("Channel %s: %s (session %s)", channel_name,
122 lttng_strerror(ret), session_name);
123 warn = 1;
26cc6b4e 124 } else {
7885e399 125 MSG("%s channel %s disabled for session %s",
ae856491 126 opt_kernel ? "Kernel" : "UST", channel_name, session_name);
26cc6b4e
DG
127 }
128
129 /* Next channel */
130 channel_name = strtok(NULL, ",");
131 }
132
ae856491
DG
133 ret = CMD_SUCCESS;
134
26cc6b4e 135error:
ae856491
DG
136 if (warn) {
137 ret = CMD_WARNING;
138 }
139
cd80958d
DG
140 lttng_destroy_handle(handle);
141
26cc6b4e
DG
142 return ret;
143}
144
145/*
146 * cmd_disable_channels
147 *
148 * Disable channel to trace session
149 */
150int cmd_disable_channels(int argc, const char **argv)
151{
ca1c3607 152 int opt, ret = CMD_SUCCESS;
26cc6b4e 153 static poptContext pc;
cd80958d 154 char *session_name = NULL;
26cc6b4e
DG
155
156 pc = poptGetContext(NULL, argc, argv, long_options, 0);
157 poptReadDefaultConfig(pc, 0);
158
159 while ((opt = poptGetNextOpt(pc)) != -1) {
160 switch (opt) {
161 case OPT_HELP:
ca1c3607 162 usage(stdout);
26cc6b4e
DG
163 goto end;
164 case OPT_USERSPACE:
165 opt_userspace = 1;
166 break;
679b4943
SM
167 case OPT_LIST_OPTIONS:
168 list_cmd_options(stdout, long_options);
679b4943 169 goto end;
26cc6b4e
DG
170 default:
171 usage(stderr);
172 ret = CMD_UNDEFINED;
173 goto end;
174 }
175 }
176
177 opt_channels = (char*) poptGetArg(pc);
178 if (opt_channels == NULL) {
179 ERR("Missing channel name(s).\n");
180 usage(stderr);
ca1c3607 181 ret = CMD_ERROR;
26cc6b4e
DG
182 goto end;
183 }
184
cd80958d
DG
185 if (!opt_session_name) {
186 session_name = get_session_name();
187 if (session_name == NULL) {
ca1c3607 188 ret = CMD_ERROR;
cd80958d
DG
189 goto end;
190 }
191 } else {
192 session_name = opt_session_name;
193 }
194
195 ret = disable_channels(session_name);
26cc6b4e
DG
196
197end:
5853fd43
DG
198 if (!opt_session_name && session_name) {
199 free(session_name);
200 }
ca1c3607 201 poptFreeContext(pc);
26cc6b4e
DG
202 return ret;
203}
This page took 0.035314 seconds and 4 git commands to generate.