Add a '--list-options' option to each command.
[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");
5440dc42 73 fprintf(ofp, " -s, --session Apply on session name\n");
78f0bacd 74 fprintf(ofp, " -k, --kernel Apply for the kernel tracer\n");
d78d6610 75#if 0
78f0bacd 76 fprintf(ofp, " -u, --userspace [CMD] Apply for 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
DG
80#else
81 fprintf(ofp, " -u, --userspace Apply for the user-space tracer\n");
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
DG
90{
91 int ret = CMD_SUCCESS;
92 char *channel_name;
7d29a247 93 struct lttng_domain dom;
26cc6b4e 94
d78d6610 95 /* Create lttng domain */
7d29a247
DG
96 if (opt_kernel) {
97 dom.type = LTTNG_DOMAIN_KERNEL;
d78d6610 98 } else if (opt_userspace) {
78f0bacd 99 dom.type = LTTNG_DOMAIN_UST;
78f0bacd 100 } else {
e14f64a8 101 ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
1ab1ea0b 102 ret = CMD_UNDEFINED;
78f0bacd 103 goto error;
7d29a247
DG
104 }
105
cd80958d
DG
106 handle = lttng_create_handle(session_name, &dom);
107 if (handle == NULL) {
108 ret = -1;
109 goto error;
110 }
111
26cc6b4e
DG
112 /* Strip channel list */
113 channel_name = strtok(opt_channels, ",");
114 while (channel_name != NULL) {
78f0bacd
DG
115 DBG("Disabling channel %s", channel_name);
116
117 ret = lttng_disable_channel(handle, channel_name);
118 if (ret < 0) {
26cc6b4e
DG
119 goto error;
120 } else {
7885e399
DG
121 MSG("%s channel %s disabled for session %s",
122 opt_kernel ? "Kernel" : "UST", channel_name,
78f0bacd 123 session_name);
26cc6b4e
DG
124 }
125
126 /* Next channel */
127 channel_name = strtok(NULL, ",");
128 }
129
130error:
cd80958d
DG
131 lttng_destroy_handle(handle);
132
26cc6b4e
DG
133 return ret;
134}
135
136/*
137 * cmd_disable_channels
138 *
139 * Disable channel to trace session
140 */
141int cmd_disable_channels(int argc, const char **argv)
142{
143 int opt, ret;
144 static poptContext pc;
cd80958d 145 char *session_name = NULL;
26cc6b4e
DG
146
147 pc = poptGetContext(NULL, argc, argv, long_options, 0);
148 poptReadDefaultConfig(pc, 0);
149
150 while ((opt = poptGetNextOpt(pc)) != -1) {
151 switch (opt) {
152 case OPT_HELP:
153 usage(stderr);
154 ret = CMD_SUCCESS;
155 goto end;
156 case OPT_USERSPACE:
157 opt_userspace = 1;
158 break;
679b4943
SM
159 case OPT_LIST_OPTIONS:
160 list_cmd_options(stdout, long_options);
161 ret = CMD_SUCCESS;
162 goto end;
26cc6b4e
DG
163 default:
164 usage(stderr);
165 ret = CMD_UNDEFINED;
166 goto end;
167 }
168 }
169
170 opt_channels = (char*) poptGetArg(pc);
171 if (opt_channels == NULL) {
172 ERR("Missing channel name(s).\n");
173 usage(stderr);
174 ret = CMD_SUCCESS;
175 goto end;
176 }
177
cd80958d
DG
178 if (!opt_session_name) {
179 session_name = get_session_name();
180 if (session_name == NULL) {
181 ret = -1;
182 goto end;
183 }
184 } else {
185 session_name = opt_session_name;
186 }
187
188 ret = disable_channels(session_name);
26cc6b4e
DG
189
190end:
191 return ret;
192}
This page took 0.047959 seconds and 4 git commands to generate.