Commit | Line | Data |
---|---|---|
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 | ||
6e2d116c DG |
28 | #include "../cmd.h" |
29 | #include "../conf.h" | |
30 | #include "../utils.h" | |
26cc6b4e DG |
31 | |
32 | static char *opt_channels; | |
e14f64a8 | 33 | static int opt_kernel; |
5440dc42 | 34 | static char *opt_session_name; |
26cc6b4e | 35 | static int opt_userspace; |
eeac7d46 | 36 | static char *opt_cmd_name; |
26cc6b4e DG |
37 | static pid_t opt_pid; |
38 | ||
39 | enum { | |
40 | OPT_HELP = 1, | |
41 | OPT_USERSPACE, | |
42 | }; | |
43 | ||
cd80958d DG |
44 | static struct lttng_handle *handle; |
45 | ||
26cc6b4e DG |
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}, | |
5440dc42 | 49 | {"session", 's', POPT_ARG_STRING, &opt_session_name, 0, 0, 0}, |
26cc6b4e | 50 | {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0}, |
6caa2bcc | 51 | {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_cmd_name, OPT_USERSPACE, 0, 0}, |
26cc6b4e DG |
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"); | |
78f0bacd | 63 | fprintf(ofp, " -h, --help Show this help\n"); |
5440dc42 | 64 | fprintf(ofp, " -s, --session Apply on session name\n"); |
78f0bacd DG |
65 | fprintf(ofp, " -k, --kernel Apply for the kernel tracer\n"); |
66 | fprintf(ofp, " -u, --userspace [CMD] Apply for the user-space tracer\n"); | |
e14f64a8 DG |
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"); | |
26cc6b4e DG |
70 | fprintf(ofp, "\n"); |
71 | } | |
72 | ||
73 | /* | |
cd80958d | 74 | * Disabling channel using the lttng API. |
26cc6b4e | 75 | */ |
cd80958d | 76 | static int disable_channels(char *session_name) |
26cc6b4e DG |
77 | { |
78 | int ret = CMD_SUCCESS; | |
79 | char *channel_name; | |
7d29a247 | 80 | struct lttng_domain dom; |
26cc6b4e | 81 | |
7d29a247 DG |
82 | if (opt_kernel) { |
83 | dom.type = LTTNG_DOMAIN_KERNEL; | |
78f0bacd DG |
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 { | |
e14f64a8 | 94 | ERR("Please specify a tracer (-k/--kernel or -u/--userspace)"); |
78f0bacd DG |
95 | ret = CMD_NOT_IMPLEMENTED; |
96 | goto error; | |
7d29a247 DG |
97 | } |
98 | ||
cd80958d DG |
99 | handle = lttng_create_handle(session_name, &dom); |
100 | if (handle == NULL) { | |
101 | ret = -1; | |
102 | goto error; | |
103 | } | |
104 | ||
26cc6b4e DG |
105 | /* Strip channel list */ |
106 | channel_name = strtok(opt_channels, ","); | |
107 | while (channel_name != NULL) { | |
78f0bacd DG |
108 | DBG("Disabling channel %s", channel_name); |
109 | ||
110 | ret = lttng_disable_channel(handle, channel_name); | |
111 | if (ret < 0) { | |
26cc6b4e DG |
112 | goto error; |
113 | } else { | |
78f0bacd DG |
114 | MSG("Channel %s disabled for session %s", channel_name, |
115 | session_name); | |
26cc6b4e DG |
116 | } |
117 | ||
118 | /* Next channel */ | |
119 | channel_name = strtok(NULL, ","); | |
120 | } | |
121 | ||
122 | error: | |
cd80958d DG |
123 | lttng_destroy_handle(handle); |
124 | ||
26cc6b4e DG |
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; | |
cd80958d | 137 | char *session_name = NULL; |
26cc6b4e DG |
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 | ||
cd80958d DG |
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); | |
26cc6b4e DG |
177 | |
178 | end: | |
179 | return ret; | |
180 | } |