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