Commit | Line | Data |
---|---|---|
d36b8583 DG |
1 | /* |
2 | * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca> | |
3 | * | |
d14d33bf AM |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License, version 2 only, | |
6 | * as published by the Free Software Foundation. | |
d36b8583 DG |
7 | * |
8 | * This program is distributed in the hope that it will be useful, | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | * GNU General Public License for more details. | |
12 | * | |
d14d33bf AM |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., | |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
d36b8583 DG |
16 | */ |
17 | ||
18 | #define _GNU_SOURCE | |
19 | #include <popt.h> | |
20 | #include <stdio.h> | |
21 | #include <stdlib.h> | |
22 | #include <string.h> | |
23 | #include <sys/stat.h> | |
24 | #include <sys/types.h> | |
25 | #include <unistd.h> | |
5a0de755 | 26 | #include <inttypes.h> |
1cb514ce MD |
27 | #include <assert.h> |
28 | #include <ctype.h> | |
d36b8583 | 29 | |
c399183f | 30 | #include "../command.h" |
1cb514ce | 31 | #include "../utils.h" |
d36b8583 | 32 | |
42224349 | 33 | #include <src/common/sessiond-comm/sessiond-comm.h> |
70d0b120 | 34 | #include <src/common/utils.h> |
42224349 | 35 | |
d36b8583 | 36 | static char *opt_channels; |
5edd7e09 | 37 | static int opt_kernel; |
5440dc42 | 38 | static char *opt_session_name; |
d36b8583 | 39 | static int opt_userspace; |
d78d6610 | 40 | static struct lttng_channel chan; |
a79d84dd | 41 | static char *opt_output; |
7972aab2 DG |
42 | static int opt_buffer_uid; |
43 | static int opt_buffer_pid; | |
44 | static int opt_buffer_global; | |
d36b8583 DG |
45 | |
46 | enum { | |
47 | OPT_HELP = 1, | |
7d29a247 DG |
48 | OPT_DISCARD, |
49 | OPT_OVERWRITE, | |
50 | OPT_SUBBUF_SIZE, | |
51 | OPT_NUM_SUBBUF, | |
52 | OPT_SWITCH_TIMER, | |
53 | OPT_READ_TIMER, | |
d36b8583 | 54 | OPT_USERSPACE, |
679b4943 | 55 | OPT_LIST_OPTIONS, |
1624d5b7 JD |
56 | OPT_TRACEFILE_SIZE, |
57 | OPT_TRACEFILE_COUNT, | |
d36b8583 DG |
58 | }; |
59 | ||
cd80958d DG |
60 | static struct lttng_handle *handle; |
61 | ||
a79d84dd DG |
62 | const char *output_mmap = "mmap"; |
63 | const char *output_splice = "splice"; | |
64 | ||
d36b8583 DG |
65 | static struct poptOption long_options[] = { |
66 | /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ | |
67 | {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0}, | |
5440dc42 | 68 | {"session", 's', POPT_ARG_STRING, &opt_session_name, 0, 0, 0}, |
d36b8583 | 69 | {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0}, |
d78d6610 | 70 | {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0}, |
7d29a247 DG |
71 | {"discard", 0, POPT_ARG_NONE, 0, OPT_DISCARD, 0, 0}, |
72 | {"overwrite", 0, POPT_ARG_NONE, 0, OPT_OVERWRITE, 0, 0}, | |
70d0b120 | 73 | {"subbuf-size", 0, POPT_ARG_STRING, 0, OPT_SUBBUF_SIZE, 0, 0}, |
1b579521 DG |
74 | {"num-subbuf", 0, POPT_ARG_INT, 0, OPT_NUM_SUBBUF, 0, 0}, |
75 | {"switch-timer", 0, POPT_ARG_INT, 0, OPT_SWITCH_TIMER, 0, 0}, | |
76 | {"read-timer", 0, POPT_ARG_INT, 0, OPT_READ_TIMER, 0, 0}, | |
679b4943 | 77 | {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL}, |
a79d84dd | 78 | {"output", 0, POPT_ARG_STRING, &opt_output, 0, 0, 0}, |
7972aab2 DG |
79 | {"buffers-uid", 0, POPT_ARG_VAL, &opt_buffer_uid, 1, 0, 0}, |
80 | {"buffers-pid", 0, POPT_ARG_VAL, &opt_buffer_pid, 1, 0, 0}, | |
81 | {"buffers-global", 0, POPT_ARG_VAL, &opt_buffer_global, 1, 0, 0}, | |
1624d5b7 JD |
82 | {"tracefile-size", 'C', POPT_ARG_INT, 0, OPT_TRACEFILE_SIZE, 0, 0}, |
83 | {"tracefile-count", 'W', POPT_ARG_INT, 0, OPT_TRACEFILE_COUNT, 0, 0}, | |
d36b8583 DG |
84 | {0, 0, 0, 0, 0, 0, 0} |
85 | }; | |
86 | ||
87 | /* | |
88 | * usage | |
89 | */ | |
90 | static void usage(FILE *ofp) | |
91 | { | |
32a6298d | 92 | fprintf(ofp, "usage: lttng enable-channel NAME[,NAME2,...] [-u|-k] [OPTIONS]\n"); |
d36b8583 | 93 | fprintf(ofp, "\n"); |
32a6298d | 94 | fprintf(ofp, "Options:\n"); |
7d29a247 | 95 | fprintf(ofp, " -h, --help Show this help\n"); |
679b4943 | 96 | fprintf(ofp, " --list-options Simple listing of options\n"); |
32a6298d | 97 | fprintf(ofp, " -s, --session NAME Apply to session name\n"); |
27221701 | 98 | fprintf(ofp, " -k, --kernel Apply to the kernel tracer\n"); |
27221701 | 99 | fprintf(ofp, " -u, --userspace Apply to the user-space tracer\n"); |
7d29a247 DG |
100 | fprintf(ofp, "\n"); |
101 | fprintf(ofp, "Channel options:\n"); | |
cabd9892 MD |
102 | fprintf(ofp, " --discard Discard event when buffers are full%s\n", |
103 | DEFAULT_CHANNEL_OVERWRITE ? "" : " (default)"); | |
104 | fprintf(ofp, " --overwrite Flight recorder mode%s\n", | |
105 | DEFAULT_CHANNEL_OVERWRITE ? " (default)" : ""); | |
70d0b120 | 106 | fprintf(ofp, " --subbuf-size SIZE Subbuffer size in bytes {+k,+M,+G}\n"); |
0a9c6494 DG |
107 | fprintf(ofp, " (default UST uid: %zu, UST pid: %zu, kernel: %zu, metadata: %zu)\n", |
108 | default_get_ust_uid_channel_subbuf_size(), | |
109 | default_get_ust_pid_channel_subbuf_size(), | |
110 | default_get_kernel_channel_subbuf_size(), | |
111 | default_get_metadata_subbuf_size()); | |
1cb514ce | 112 | fprintf(ofp, " Rounded up to the next power of 2.\n"); |
cc62c0c0 | 113 | fprintf(ofp, " --num-subbuf NUM Number of subbufers\n"); |
0a9c6494 DG |
114 | fprintf(ofp, " (default UST uid: %u, UST pid: %u, kernel: %u, metadata: %u)\n", |
115 | DEFAULT_UST_UID_CHANNEL_SUBBUF_NUM, DEFAULT_UST_PID_CHANNEL_SUBBUF_NUM, | |
116 | DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM, DEFAULT_METADATA_SUBBUF_NUM); | |
1cb514ce | 117 | fprintf(ofp, " Rounded up to the next power of 2.\n"); |
0a9c6494 DG |
118 | fprintf(ofp, " --switch-timer USEC Switch timer interval in usec\n"); |
119 | fprintf(ofp, " (default UST uid: %u, UST pid: %u, kernel: %u, metadata: %u)\n", | |
120 | DEFAULT_UST_UID_CHANNEL_SWITCH_TIMER, DEFAULT_UST_PID_CHANNEL_SWITCH_TIMER, | |
121 | DEFAULT_KERNEL_CHANNEL_SWITCH_TIMER, DEFAULT_METADATA_SWITCH_TIMER); | |
122 | fprintf(ofp, " --read-timer USEC Read timer interval in usec.\n"); | |
123 | fprintf(ofp, " (default UST uid: %u, UST pid: %u, kernel: %u, metadata: %u)\n", | |
124 | DEFAULT_UST_UID_CHANNEL_READ_TIMER, DEFAULT_UST_UID_CHANNEL_READ_TIMER, | |
125 | DEFAULT_KERNEL_CHANNEL_READ_TIMER, DEFAULT_METADATA_READ_TIMER); | |
a79d84dd DG |
126 | fprintf(ofp, " --output TYPE Channel output type (Values: %s, %s)\n", |
127 | output_mmap, output_splice); | |
0a9c6494 DG |
128 | fprintf(ofp, " (default UST uid: %s, UST pid: %s, kernel: %s, metadata: %s)\n", |
129 | DEFAULT_UST_UID_CHANNEL_OUTPUT == LTTNG_EVENT_MMAP ? output_mmap : output_splice, | |
130 | DEFAULT_UST_PID_CHANNEL_OUTPUT == LTTNG_EVENT_MMAP ? output_mmap : output_splice, | |
131 | DEFAULT_KERNEL_CHANNEL_OUTPUT == LTTNG_EVENT_MMAP ? output_mmap : output_splice, | |
132 | DEFAULT_METADATA_OUTPUT == LTTNG_EVENT_MMAP ? output_mmap : output_splice); | |
7972aab2 DG |
133 | fprintf(ofp, " --buffers-uid Use per UID buffer (-u only)\n"); |
134 | fprintf(ofp, " --buffers-pid Use per PID buffer (-u only)\n"); | |
135 | fprintf(ofp, " --buffers-global Use shared buffer for the whole system (-k only)\n"); | |
1624d5b7 | 136 | fprintf(ofp, " -C, --tracefile-size SIZE\n"); |
0a9c6494 DG |
137 | fprintf(ofp, " Maximum size of each tracefile within a stream (in bytes). 0 means unlimited.\n"); |
138 | fprintf(ofp, " (default: %u)\n", DEFAULT_CHANNEL_TRACEFILE_SIZE); | |
1624d5b7 JD |
139 | fprintf(ofp, " -W, --tracefile-count COUNT\n"); |
140 | fprintf(ofp, " Used in conjunction with -C option, this will limit the number\n"); | |
0a9c6494 DG |
141 | fprintf(ofp, " of files created to the specified count. 0 means unlimited.\n"); |
142 | fprintf(ofp, " (default: %u)\n", DEFAULT_CHANNEL_TRACEFILE_COUNT); | |
d36b8583 DG |
143 | fprintf(ofp, "\n"); |
144 | } | |
145 | ||
5edd7e09 DG |
146 | /* |
147 | * Set default attributes depending on those already defined from the command | |
148 | * line. | |
149 | */ | |
150 | static void set_default_attr(struct lttng_domain *dom) | |
151 | { | |
152 | struct lttng_channel_attr default_attr; | |
153 | ||
154 | /* Set attributes */ | |
155 | lttng_channel_set_default_attr(dom, &default_attr); | |
156 | ||
157 | if (chan.attr.overwrite == -1) { | |
158 | chan.attr.overwrite = default_attr.overwrite; | |
159 | } | |
160 | if (chan.attr.subbuf_size == -1) { | |
161 | chan.attr.subbuf_size = default_attr.subbuf_size; | |
162 | } | |
163 | if (chan.attr.num_subbuf == -1) { | |
164 | chan.attr.num_subbuf = default_attr.num_subbuf; | |
165 | } | |
166 | if (chan.attr.switch_timer_interval == -1) { | |
167 | chan.attr.switch_timer_interval = default_attr.switch_timer_interval; | |
168 | } | |
169 | if (chan.attr.read_timer_interval == -1) { | |
170 | chan.attr.read_timer_interval = default_attr.read_timer_interval; | |
171 | } | |
172 | if (chan.attr.output == -1) { | |
173 | chan.attr.output = default_attr.output; | |
174 | } | |
1624d5b7 JD |
175 | if (chan.attr.tracefile_count == -1) { |
176 | chan.attr.tracefile_count = default_attr.tracefile_count; | |
177 | } | |
178 | if (chan.attr.tracefile_size == -1) { | |
179 | chan.attr.tracefile_size = default_attr.tracefile_size; | |
180 | } | |
5edd7e09 DG |
181 | } |
182 | ||
d36b8583 | 183 | /* |
0fdd1e2c | 184 | * Adding channel using the lttng API. |
d36b8583 | 185 | */ |
cd80958d | 186 | static int enable_channel(char *session_name) |
d36b8583 | 187 | { |
ae856491 | 188 | int ret = CMD_SUCCESS, warn = 0; |
d36b8583 | 189 | char *channel_name; |
7d29a247 | 190 | struct lttng_domain dom; |
d36b8583 | 191 | |
441c16a7 MD |
192 | memset(&dom, 0, sizeof(dom)); |
193 | ||
d78d6610 | 194 | /* Create lttng domain */ |
7d29a247 DG |
195 | if (opt_kernel) { |
196 | dom.type = LTTNG_DOMAIN_KERNEL; | |
7972aab2 | 197 | dom.buf_type = LTTNG_BUFFER_GLOBAL; |
88c5f0d8 DG |
198 | if (opt_buffer_uid || opt_buffer_pid) { |
199 | ERR("Buffer type not supported for domain -k"); | |
200 | ret = CMD_ERROR; | |
201 | goto error; | |
202 | } | |
d78d6610 | 203 | } else if (opt_userspace) { |
f6a9efaa | 204 | dom.type = LTTNG_DOMAIN_UST; |
7972aab2 DG |
205 | if (opt_buffer_uid) { |
206 | dom.buf_type = LTTNG_BUFFER_PER_UID; | |
207 | } else { | |
88c5f0d8 DG |
208 | if (opt_buffer_global) { |
209 | ERR("Buffer type not supported for domain -u"); | |
210 | ret = CMD_ERROR; | |
211 | goto error; | |
212 | } | |
7972aab2 DG |
213 | dom.buf_type = LTTNG_BUFFER_PER_PID; |
214 | } | |
0fdd1e2c | 215 | } else { |
e14f64a8 | 216 | ERR("Please specify a tracer (-k/--kernel or -u/--userspace)"); |
d16c1a4c | 217 | ret = CMD_ERROR; |
0fdd1e2c | 218 | goto error; |
7d29a247 DG |
219 | } |
220 | ||
5edd7e09 DG |
221 | set_default_attr(&dom); |
222 | ||
1624d5b7 JD |
223 | if ((chan.attr.tracefile_size > 0) && |
224 | (chan.attr.tracefile_size < chan.attr.subbuf_size)) { | |
de65565a | 225 | WARN("Tracefile size rounded up from (%" PRIu64 ") to subbuffer size (%" PRIu64 ")", |
1624d5b7 | 226 | chan.attr.tracefile_size, chan.attr.subbuf_size); |
de65565a | 227 | chan.attr.tracefile_size = chan.attr.subbuf_size; |
1624d5b7 JD |
228 | } |
229 | ||
a79d84dd DG |
230 | /* Setting channel output */ |
231 | if (opt_output) { | |
232 | if (!strncmp(output_mmap, opt_output, strlen(output_mmap))) { | |
233 | chan.attr.output = LTTNG_EVENT_MMAP; | |
234 | } else if (!strncmp(output_splice, opt_output, strlen(output_splice))) { | |
235 | chan.attr.output = LTTNG_EVENT_SPLICE; | |
236 | } else { | |
237 | ERR("Unknown output type %s. Possible values are: %s, %s\n", | |
238 | opt_output, output_mmap, output_splice); | |
239 | usage(stderr); | |
240 | ret = CMD_ERROR; | |
241 | goto error; | |
242 | } | |
243 | } | |
244 | ||
cd80958d DG |
245 | handle = lttng_create_handle(session_name, &dom); |
246 | if (handle == NULL) { | |
247 | ret = -1; | |
248 | goto error; | |
249 | } | |
250 | ||
0fdd1e2c | 251 | /* Strip channel list (format: chan1,chan2,...) */ |
d36b8583 DG |
252 | channel_name = strtok(opt_channels, ","); |
253 | while (channel_name != NULL) { | |
0fdd1e2c DG |
254 | /* Copy channel name and normalize it */ |
255 | strncpy(chan.name, channel_name, NAME_MAX); | |
256 | chan.name[NAME_MAX - 1] = '\0'; | |
257 | ||
258 | DBG("Enabling channel %s", channel_name); | |
259 | ||
260 | ret = lttng_enable_channel(handle, &chan); | |
261 | if (ret < 0) { | |
42224349 | 262 | switch (-ret) { |
f73fabfd DG |
263 | case LTTNG_ERR_KERN_CHAN_EXIST: |
264 | case LTTNG_ERR_UST_CHAN_EXIST: | |
88c5f0d8 | 265 | WARN("Channel %s: %s (session %s)", channel_name, |
42224349 DG |
266 | lttng_strerror(ret), session_name); |
267 | goto error; | |
268 | default: | |
269 | ERR("Channel %s: %s (session %s)", channel_name, | |
270 | lttng_strerror(ret), session_name); | |
271 | break; | |
272 | } | |
ae856491 | 273 | warn = 1; |
d36b8583 | 274 | } else { |
7885e399 DG |
275 | MSG("%s channel %s enabled for session %s", |
276 | opt_kernel ? "Kernel" : "UST", channel_name, | |
277 | session_name); | |
d36b8583 DG |
278 | } |
279 | ||
280 | /* Next event */ | |
281 | channel_name = strtok(NULL, ","); | |
282 | } | |
283 | ||
ae856491 DG |
284 | ret = CMD_SUCCESS; |
285 | ||
d36b8583 | 286 | error: |
ae856491 DG |
287 | if (warn) { |
288 | ret = CMD_WARNING; | |
289 | } | |
290 | ||
cd80958d DG |
291 | lttng_destroy_handle(handle); |
292 | ||
d36b8583 DG |
293 | return ret; |
294 | } | |
295 | ||
296 | /* | |
0fdd1e2c | 297 | * Default value for channel configuration. |
7d29a247 DG |
298 | */ |
299 | static void init_channel_config(void) | |
300 | { | |
5edd7e09 DG |
301 | /* |
302 | * Put -1 everywhere so we can identify those set by the command line and | |
303 | * those needed to be set by the default values. | |
304 | */ | |
305 | memset(&chan.attr, -1, sizeof(chan.attr)); | |
7d29a247 DG |
306 | } |
307 | ||
308 | /* | |
0fdd1e2c | 309 | * Add channel to trace session |
d36b8583 DG |
310 | */ |
311 | int cmd_enable_channels(int argc, const char **argv) | |
312 | { | |
ca1c3607 | 313 | int opt, ret = CMD_SUCCESS; |
d36b8583 | 314 | static poptContext pc; |
cd80958d | 315 | char *session_name = NULL; |
70d0b120 | 316 | char *opt_arg = NULL; |
d36b8583 | 317 | |
7d29a247 DG |
318 | init_channel_config(); |
319 | ||
d36b8583 DG |
320 | pc = poptGetContext(NULL, argc, argv, long_options, 0); |
321 | poptReadDefaultConfig(pc, 0); | |
322 | ||
323 | while ((opt = poptGetNextOpt(pc)) != -1) { | |
324 | switch (opt) { | |
325 | case OPT_HELP: | |
ca1c3607 | 326 | usage(stdout); |
d36b8583 | 327 | goto end; |
7d29a247 DG |
328 | case OPT_DISCARD: |
329 | chan.attr.overwrite = 0; | |
330 | DBG("Channel set to discard"); | |
331 | break; | |
332 | case OPT_OVERWRITE: | |
333 | chan.attr.overwrite = 1; | |
334 | DBG("Channel set to overwrite"); | |
335 | break; | |
336 | case OPT_SUBBUF_SIZE: | |
1cb514ce MD |
337 | { |
338 | uint64_t rounded_size; | |
339 | int order; | |
340 | ||
70d0b120 SM |
341 | /* Parse the size */ |
342 | opt_arg = poptGetOptArg(pc); | |
1cb514ce MD |
343 | if (utils_parse_size_suffix(opt_arg, &chan.attr.subbuf_size) < 0 || !chan.attr.subbuf_size) { |
344 | ERR("Wrong value in --subbuf-size parameter: %s", opt_arg); | |
70d0b120 SM |
345 | ret = CMD_ERROR; |
346 | goto end; | |
347 | } | |
348 | ||
1cb514ce MD |
349 | order = get_count_order_u64(chan.attr.subbuf_size); |
350 | assert(order >= 0); | |
351 | rounded_size = 1ULL << order; | |
352 | if (rounded_size != chan.attr.subbuf_size) { | |
353 | WARN("The subbuf size (%" PRIu64 ") is rounded to the next power of 2 (%" PRIu64 ")", | |
354 | chan.attr.subbuf_size, rounded_size); | |
355 | chan.attr.subbuf_size = rounded_size; | |
70d0b120 SM |
356 | } |
357 | ||
1cb514ce MD |
358 | /* Should now be power of 2 */ |
359 | assert(!((chan.attr.subbuf_size - 1) & chan.attr.subbuf_size)); | |
360 | ||
5a0de755 | 361 | DBG("Channel subbuf size set to %" PRIu64, chan.attr.subbuf_size); |
7d29a247 | 362 | break; |
1cb514ce | 363 | } |
7d29a247 | 364 | case OPT_NUM_SUBBUF: |
1cb514ce MD |
365 | { |
366 | uint64_t rounded_size; | |
367 | int order; | |
368 | ||
16068db5 | 369 | errno = 0; |
1cb514ce MD |
370 | opt_arg = poptGetOptArg(pc); |
371 | chan.attr.num_subbuf = strtoull(opt_arg, NULL, 0); | |
372 | if (errno != 0 || !chan.attr.num_subbuf || !isdigit(opt_arg[0])) { | |
373 | ERR("Wrong value in --num-subbuf parameter: %s", opt_arg); | |
16068db5 MD |
374 | ret = CMD_ERROR; |
375 | goto end; | |
376 | } | |
377 | ||
1cb514ce MD |
378 | order = get_count_order_u64(chan.attr.num_subbuf); |
379 | assert(order >= 0); | |
380 | rounded_size = 1ULL << order; | |
381 | if (rounded_size != chan.attr.num_subbuf) { | |
382 | WARN("The number of subbuffers (%" PRIu64 ") is rounded to the next power of 2 (%" PRIu64 ")", | |
383 | chan.attr.num_subbuf, rounded_size); | |
384 | chan.attr.num_subbuf = rounded_size; | |
385 | } | |
386 | ||
387 | /* Should now be power of 2 */ | |
388 | assert(!((chan.attr.num_subbuf - 1) & chan.attr.num_subbuf)); | |
389 | ||
5a0de755 | 390 | DBG("Channel subbuf num set to %" PRIu64, chan.attr.num_subbuf); |
7d29a247 | 391 | break; |
1cb514ce | 392 | } |
7d29a247 | 393 | case OPT_SWITCH_TIMER: |
16068db5 MD |
394 | { |
395 | unsigned long v; | |
396 | ||
397 | errno = 0; | |
1cb514ce MD |
398 | opt_arg = poptGetOptArg(pc); |
399 | v = strtoul(opt_arg, NULL, 0); | |
400 | if (errno != 0 || !isdigit(opt_arg[0])) { | |
401 | ERR("Wrong value in --switch-timer parameter: %s", opt_arg); | |
16068db5 MD |
402 | ret = CMD_ERROR; |
403 | goto end; | |
404 | } | |
405 | if (v != (uint32_t) v) { | |
406 | ERR("32-bit overflow in --switch-timer parameter: %s", opt_arg); | |
407 | ret = CMD_ERROR; | |
408 | goto end; | |
409 | } | |
410 | chan.attr.switch_timer_interval = (uint32_t) v; | |
7d29a247 DG |
411 | DBG("Channel switch timer interval set to %d", chan.attr.switch_timer_interval); |
412 | break; | |
16068db5 | 413 | } |
7d29a247 | 414 | case OPT_READ_TIMER: |
16068db5 MD |
415 | { |
416 | unsigned long v; | |
417 | ||
418 | errno = 0; | |
1cb514ce MD |
419 | opt_arg = poptGetOptArg(pc); |
420 | v = strtoul(opt_arg, NULL, 0); | |
421 | if (errno != 0 || !isdigit(opt_arg[0])) { | |
422 | ERR("Wrong value in --read-timer parameter: %s", opt_arg); | |
16068db5 MD |
423 | ret = CMD_ERROR; |
424 | goto end; | |
425 | } | |
426 | if (v != (uint32_t) v) { | |
427 | ERR("32-bit overflow in --read-timer parameter: %s", opt_arg); | |
428 | ret = CMD_ERROR; | |
429 | goto end; | |
430 | } | |
431 | chan.attr.read_timer_interval = (uint32_t) v; | |
7d29a247 | 432 | DBG("Channel read timer interval set to %d", chan.attr.read_timer_interval); |
d36b8583 | 433 | break; |
16068db5 | 434 | } |
eeac7d46 MD |
435 | case OPT_USERSPACE: |
436 | opt_userspace = 1; | |
eeac7d46 | 437 | break; |
1624d5b7 | 438 | case OPT_TRACEFILE_SIZE: |
1cb514ce | 439 | opt_arg = poptGetOptArg(pc); |
16068db5 | 440 | if (utils_parse_size_suffix(opt_arg, &chan.attr.tracefile_size) < 0) { |
1cb514ce | 441 | ERR("Wrong value in --tracefile-size parameter: %s", opt_arg); |
16068db5 MD |
442 | ret = CMD_ERROR; |
443 | goto end; | |
444 | } | |
1624d5b7 JD |
445 | DBG("Maximum tracefile size set to %" PRIu64, |
446 | chan.attr.tracefile_size); | |
447 | break; | |
448 | case OPT_TRACEFILE_COUNT: | |
16068db5 MD |
449 | { |
450 | unsigned long v; | |
451 | ||
452 | errno = 0; | |
1cb514ce MD |
453 | opt_arg = poptGetOptArg(pc); |
454 | v = strtoul(opt_arg, NULL, 0); | |
455 | if (errno != 0 || !isdigit(opt_arg[0])) { | |
456 | ERR("Wrong value in --tracefile-count parameter: %s", opt_arg); | |
16068db5 MD |
457 | ret = CMD_ERROR; |
458 | goto end; | |
459 | } | |
460 | if (v != (uint32_t) v) { | |
461 | ERR("32-bit overflow in --tracefile-count parameter: %s", opt_arg); | |
462 | ret = CMD_ERROR; | |
463 | goto end; | |
464 | } | |
465 | chan.attr.tracefile_count = (uint32_t) v; | |
1624d5b7 JD |
466 | DBG("Maximum tracefile count set to %" PRIu64, |
467 | chan.attr.tracefile_count); | |
468 | break; | |
16068db5 | 469 | } |
679b4943 SM |
470 | case OPT_LIST_OPTIONS: |
471 | list_cmd_options(stdout, long_options); | |
679b4943 | 472 | goto end; |
d36b8583 DG |
473 | default: |
474 | usage(stderr); | |
475 | ret = CMD_UNDEFINED; | |
476 | goto end; | |
477 | } | |
478 | } | |
479 | ||
480 | opt_channels = (char*) poptGetArg(pc); | |
481 | if (opt_channels == NULL) { | |
7d29a247 | 482 | ERR("Missing channel name.\n"); |
d36b8583 | 483 | usage(stderr); |
ca1c3607 | 484 | ret = CMD_ERROR; |
d36b8583 DG |
485 | goto end; |
486 | } | |
487 | ||
cd80958d DG |
488 | if (!opt_session_name) { |
489 | session_name = get_session_name(); | |
490 | if (session_name == NULL) { | |
ca1c3607 | 491 | ret = CMD_ERROR; |
cd80958d DG |
492 | goto end; |
493 | } | |
494 | } else { | |
495 | session_name = opt_session_name; | |
496 | } | |
497 | ||
498 | ret = enable_channel(session_name); | |
d36b8583 DG |
499 | |
500 | end: | |
5853fd43 DG |
501 | if (!opt_session_name && session_name) { |
502 | free(session_name); | |
503 | } | |
ca1c3607 | 504 | poptFreeContext(pc); |
d36b8583 DG |
505 | return ret; |
506 | } |