Change not implemented error to undefined.
[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,
43};
44
cd80958d
DG
45static struct lttng_handle *handle;
46
26cc6b4e
DG
47static struct poptOption long_options[] = {
48 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
49 {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
5440dc42 50 {"session", 's', POPT_ARG_STRING, &opt_session_name, 0, 0, 0},
26cc6b4e 51 {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
d78d6610
DG
52#if 0
53 /* Not implemented yet */
6caa2bcc 54 {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_cmd_name, OPT_USERSPACE, 0, 0},
26cc6b4e 55 {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0},
d78d6610
DG
56#else
57 {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0},
58#endif
26cc6b4e
DG
59 {0, 0, 0, 0, 0, 0, 0}
60};
61
62/*
63 * usage
64 */
65static void usage(FILE *ofp)
66{
67 fprintf(ofp, "usage: lttng disable-channel NAME[,NAME2,...] [options]\n");
68 fprintf(ofp, "\n");
78f0bacd 69 fprintf(ofp, " -h, --help Show this help\n");
5440dc42 70 fprintf(ofp, " -s, --session Apply on session name\n");
78f0bacd 71 fprintf(ofp, " -k, --kernel Apply for the kernel tracer\n");
d78d6610 72#if 0
78f0bacd 73 fprintf(ofp, " -u, --userspace [CMD] Apply for the user-space tracer\n");
e14f64a8
DG
74 fprintf(ofp, " If no CMD, the domain used is UST global\n");
75 fprintf(ofp, " or else the domain is UST EXEC_NAME\n");
76 fprintf(ofp, " -p, --pid PID If -u, apply to specific PID (domain: UST PID)\n");
d78d6610
DG
77#else
78 fprintf(ofp, " -u, --userspace Apply for the user-space tracer\n");
79#endif
26cc6b4e
DG
80 fprintf(ofp, "\n");
81}
82
83/*
cd80958d 84 * Disabling channel using the lttng API.
26cc6b4e 85 */
cd80958d 86static int disable_channels(char *session_name)
26cc6b4e
DG
87{
88 int ret = CMD_SUCCESS;
89 char *channel_name;
7d29a247 90 struct lttng_domain dom;
26cc6b4e 91
d78d6610 92 /* Create lttng domain */
7d29a247
DG
93 if (opt_kernel) {
94 dom.type = LTTNG_DOMAIN_KERNEL;
d78d6610 95 } else if (opt_userspace) {
78f0bacd 96 dom.type = LTTNG_DOMAIN_UST;
78f0bacd 97 } else {
e14f64a8 98 ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
1ab1ea0b 99 ret = CMD_UNDEFINED;
78f0bacd 100 goto error;
7d29a247
DG
101 }
102
cd80958d
DG
103 handle = lttng_create_handle(session_name, &dom);
104 if (handle == NULL) {
105 ret = -1;
106 goto error;
107 }
108
26cc6b4e
DG
109 /* Strip channel list */
110 channel_name = strtok(opt_channels, ",");
111 while (channel_name != NULL) {
78f0bacd
DG
112 DBG("Disabling channel %s", channel_name);
113
114 ret = lttng_disable_channel(handle, channel_name);
115 if (ret < 0) {
26cc6b4e
DG
116 goto error;
117 } else {
7885e399
DG
118 MSG("%s channel %s disabled for session %s",
119 opt_kernel ? "Kernel" : "UST", channel_name,
78f0bacd 120 session_name);
26cc6b4e
DG
121 }
122
123 /* Next channel */
124 channel_name = strtok(NULL, ",");
125 }
126
127error:
cd80958d
DG
128 lttng_destroy_handle(handle);
129
26cc6b4e
DG
130 return ret;
131}
132
133/*
134 * cmd_disable_channels
135 *
136 * Disable channel to trace session
137 */
138int cmd_disable_channels(int argc, const char **argv)
139{
140 int opt, ret;
141 static poptContext pc;
cd80958d 142 char *session_name = NULL;
26cc6b4e
DG
143
144 pc = poptGetContext(NULL, argc, argv, long_options, 0);
145 poptReadDefaultConfig(pc, 0);
146
147 while ((opt = poptGetNextOpt(pc)) != -1) {
148 switch (opt) {
149 case OPT_HELP:
150 usage(stderr);
151 ret = CMD_SUCCESS;
152 goto end;
153 case OPT_USERSPACE:
154 opt_userspace = 1;
155 break;
156 default:
157 usage(stderr);
158 ret = CMD_UNDEFINED;
159 goto end;
160 }
161 }
162
163 opt_channels = (char*) poptGetArg(pc);
164 if (opt_channels == NULL) {
165 ERR("Missing channel name(s).\n");
166 usage(stderr);
167 ret = CMD_SUCCESS;
168 goto end;
169 }
170
cd80958d
DG
171 if (!opt_session_name) {
172 session_name = get_session_name();
173 if (session_name == NULL) {
174 ret = -1;
175 goto end;
176 }
177 } else {
178 session_name = opt_session_name;
179 }
180
181 ret = disable_channels(session_name);
26cc6b4e
DG
182
183end:
184 return ret;
185}
This page took 0.032571 seconds and 4 git commands to generate.