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