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; | |
33 | static char *opt_kernel; | |
5440dc42 | 34 | static char *opt_session_name; |
26cc6b4e DG |
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 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 DG |
48 | {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0}, |
49 | {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0}, | |
50 | {"all", 0, POPT_ARG_VAL, &opt_pid_all, 1, 0, 0}, | |
51 | {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0}, | |
52 | {0, 0, 0, 0, 0, 0, 0} | |
53 | }; | |
54 | ||
55 | /* | |
56 | * usage | |
57 | */ | |
58 | static void usage(FILE *ofp) | |
59 | { | |
60 | fprintf(ofp, "usage: lttng disable-channel NAME[,NAME2,...] [options]\n"); | |
61 | fprintf(ofp, "\n"); | |
62 | fprintf(ofp, " -h, --help Show this help\n"); | |
5440dc42 | 63 | fprintf(ofp, " -s, --session Apply on session name\n"); |
26cc6b4e DG |
64 | fprintf(ofp, " -k, --kernel Apply for the kernel tracer\n"); |
65 | fprintf(ofp, " -u, --userspace Apply for the user-space tracer\n"); | |
66 | fprintf(ofp, " --all If -u, apply on all traceable apps\n"); | |
67 | fprintf(ofp, " -p, --pid PID If -u, apply on a specific PID\n"); | |
68 | fprintf(ofp, "\n"); | |
69 | } | |
70 | ||
71 | /* | |
72 | * disable_channels | |
73 | * | |
74 | * Disabling channel using the lttng API. | |
75 | */ | |
76 | static int disable_channels(void) | |
77 | { | |
78 | int ret = CMD_SUCCESS; | |
79 | char *channel_name; | |
7d29a247 | 80 | struct lttng_domain dom; |
26cc6b4e | 81 | |
5440dc42 | 82 | if (set_session_name(opt_session_name) < 0) { |
26cc6b4e DG |
83 | ret = CMD_ERROR; |
84 | goto error; | |
85 | } | |
86 | ||
7d29a247 DG |
87 | if (opt_kernel) { |
88 | dom.type = LTTNG_DOMAIN_KERNEL; | |
89 | } | |
90 | ||
26cc6b4e DG |
91 | /* Strip channel list */ |
92 | channel_name = strtok(opt_channels, ","); | |
93 | while (channel_name != NULL) { | |
94 | /* Kernel tracer action */ | |
95 | if (opt_kernel) { | |
96 | DBG("Disabling kernel channel %s", channel_name); | |
7d29a247 | 97 | ret = lttng_disable_channel(&dom, channel_name); |
26cc6b4e DG |
98 | if (ret < 0) { |
99 | goto error; | |
100 | } else { | |
101 | MSG("Kernel channel disabled %s", channel_name); | |
102 | } | |
103 | } else if (opt_userspace) { /* User-space tracer action */ | |
104 | /* | |
105 | * TODO: Waiting on lttng UST 2.0 | |
106 | */ | |
107 | if (opt_pid_all) { | |
108 | } else if (opt_pid != 0) { | |
109 | } | |
110 | ret = CMD_NOT_IMPLEMENTED; | |
111 | goto error; | |
112 | } else { | |
113 | ERR("Please specify a tracer (kernel or user-space)"); | |
114 | goto error; | |
115 | } | |
116 | ||
117 | /* Next channel */ | |
118 | channel_name = strtok(NULL, ","); | |
119 | } | |
120 | ||
121 | error: | |
122 | return ret; | |
123 | } | |
124 | ||
125 | /* | |
126 | * cmd_disable_channels | |
127 | * | |
128 | * Disable channel to trace session | |
129 | */ | |
130 | int cmd_disable_channels(int argc, const char **argv) | |
131 | { | |
132 | int opt, ret; | |
133 | static poptContext pc; | |
134 | ||
135 | pc = poptGetContext(NULL, argc, argv, long_options, 0); | |
136 | poptReadDefaultConfig(pc, 0); | |
137 | ||
138 | while ((opt = poptGetNextOpt(pc)) != -1) { | |
139 | switch (opt) { | |
140 | case OPT_HELP: | |
141 | usage(stderr); | |
142 | ret = CMD_SUCCESS; | |
143 | goto end; | |
144 | case OPT_USERSPACE: | |
145 | opt_userspace = 1; | |
146 | break; | |
147 | default: | |
148 | usage(stderr); | |
149 | ret = CMD_UNDEFINED; | |
150 | goto end; | |
151 | } | |
152 | } | |
153 | ||
154 | opt_channels = (char*) poptGetArg(pc); | |
155 | if (opt_channels == NULL) { | |
156 | ERR("Missing channel name(s).\n"); | |
157 | usage(stderr); | |
158 | ret = CMD_SUCCESS; | |
159 | goto end; | |
160 | } | |
161 | ||
162 | ret = disable_channels(); | |
163 | ||
164 | end: | |
165 | return ret; | |
166 | } |