Change lttng command line options for UST domain
[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 int opt_kernel;
34 static char *opt_session_name;
35 static int opt_userspace;
36 static char *opt_cmd_name;
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_STRING | POPT_ARGFLAG_OPTIONAL, &opt_cmd_name, OPT_USERSPACE, 0, 0},
52 {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0},
53 {0, 0, 0, 0, 0, 0, 0}
54 };
55
56 /*
57 * usage
58 */
59 static void usage(FILE *ofp)
60 {
61 fprintf(ofp, "usage: lttng disable-channel NAME[,NAME2,...] [options]\n");
62 fprintf(ofp, "\n");
63 fprintf(ofp, " -h, --help Show this help\n");
64 fprintf(ofp, " -s, --session Apply on session name\n");
65 fprintf(ofp, " -k, --kernel Apply for the kernel tracer\n");
66 fprintf(ofp, " -u, --userspace [CMD] Apply for the user-space tracer\n");
67 fprintf(ofp, " If no CMD, the domain used is UST global\n");
68 fprintf(ofp, " or else the domain is UST EXEC_NAME\n");
69 fprintf(ofp, " -p, --pid PID If -u, apply to specific PID (domain: UST 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 } else if (opt_pid != 0) {
85 dom.type = LTTNG_DOMAIN_UST_PID;
86 dom.attr.pid = opt_pid;
87 DBG("PID %d set to lttng handle", opt_pid);
88 } else if (opt_userspace && opt_cmd_name == NULL) {
89 dom.type = LTTNG_DOMAIN_UST;
90 } else if (opt_userspace && opt_cmd_name != NULL) {
91 dom.type = LTTNG_DOMAIN_UST_EXEC_NAME;
92 strncpy(dom.attr.exec_name, opt_cmd_name, NAME_MAX);
93 } else {
94 ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
95 ret = CMD_NOT_IMPLEMENTED;
96 goto error;
97 }
98
99 handle = lttng_create_handle(session_name, &dom);
100 if (handle == NULL) {
101 ret = -1;
102 goto error;
103 }
104
105 /* Strip channel list */
106 channel_name = strtok(opt_channels, ",");
107 while (channel_name != NULL) {
108 DBG("Disabling channel %s", channel_name);
109
110 ret = lttng_disable_channel(handle, channel_name);
111 if (ret < 0) {
112 goto error;
113 } else {
114 MSG("Channel %s disabled for session %s", channel_name,
115 session_name);
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.032376 seconds and 4 git commands to generate.