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