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"); |
3e230f92 SM |
107 | fprintf(ofp, " (default: %zu, kernel default: %zu)\n", |
108 | default_get_channel_subbuf_size(), | |
109 | default_get_kernel_channel_subbuf_size()); | |
1cb514ce | 110 | fprintf(ofp, " Rounded up to the next power of 2.\n"); |
cc62c0c0 | 111 | fprintf(ofp, " --num-subbuf NUM Number of subbufers\n"); |
9f778c9a MD |
112 | fprintf(ofp, " (default: %u)\n", |
113 | DEFAULT_CHANNEL_SUBBUF_NUM); | |
1cb514ce | 114 | fprintf(ofp, " Rounded up to the next power of 2.\n"); |
cc62c0c0 | 115 | fprintf(ofp, " --switch-timer USEC Switch timer interval in usec (default: %u)\n", |
cabd9892 | 116 | DEFAULT_CHANNEL_SWITCH_TIMER); |
db77f3a3 DG |
117 | fprintf(ofp, " --read-timer USEC Read timer interval in usec (UST default: %u, kernel default: %u)\n", |
118 | DEFAULT_UST_CHANNEL_READ_TIMER, DEFAULT_KERNEL_CHANNEL_READ_TIMER); | |
a79d84dd DG |
119 | fprintf(ofp, " --output TYPE Channel output type (Values: %s, %s)\n", |
120 | output_mmap, output_splice); | |
7972aab2 DG |
121 | fprintf(ofp, " --buffers-uid Use per UID buffer (-u only)\n"); |
122 | fprintf(ofp, " --buffers-pid Use per PID buffer (-u only)\n"); | |
123 | fprintf(ofp, " --buffers-global Use shared buffer for the whole system (-k only)\n"); | |
1624d5b7 | 124 | fprintf(ofp, " -C, --tracefile-size SIZE\n"); |
e132a0d4 | 125 | fprintf(ofp, " Maximum size of each tracefile within a stream (in bytes).\n"); |
1624d5b7 JD |
126 | fprintf(ofp, " -W, --tracefile-count COUNT\n"); |
127 | fprintf(ofp, " Used in conjunction with -C option, this will limit the number\n"); | |
128 | fprintf(ofp, " of files created to the specified count.\n"); | |
d36b8583 DG |
129 | fprintf(ofp, "\n"); |
130 | } | |
131 | ||
5edd7e09 DG |
132 | /* |
133 | * Set default attributes depending on those already defined from the command | |
134 | * line. | |
135 | */ | |
136 | static void set_default_attr(struct lttng_domain *dom) | |
137 | { | |
138 | struct lttng_channel_attr default_attr; | |
139 | ||
140 | /* Set attributes */ | |
141 | lttng_channel_set_default_attr(dom, &default_attr); | |
142 | ||
143 | if (chan.attr.overwrite == -1) { | |
144 | chan.attr.overwrite = default_attr.overwrite; | |
145 | } | |
146 | if (chan.attr.subbuf_size == -1) { | |
147 | chan.attr.subbuf_size = default_attr.subbuf_size; | |
148 | } | |
149 | if (chan.attr.num_subbuf == -1) { | |
150 | chan.attr.num_subbuf = default_attr.num_subbuf; | |
151 | } | |
152 | if (chan.attr.switch_timer_interval == -1) { | |
153 | chan.attr.switch_timer_interval = default_attr.switch_timer_interval; | |
154 | } | |
155 | if (chan.attr.read_timer_interval == -1) { | |
156 | chan.attr.read_timer_interval = default_attr.read_timer_interval; | |
157 | } | |
158 | if (chan.attr.output == -1) { | |
159 | chan.attr.output = default_attr.output; | |
160 | } | |
1624d5b7 JD |
161 | if (chan.attr.tracefile_count == -1) { |
162 | chan.attr.tracefile_count = default_attr.tracefile_count; | |
163 | } | |
164 | if (chan.attr.tracefile_size == -1) { | |
165 | chan.attr.tracefile_size = default_attr.tracefile_size; | |
166 | } | |
5edd7e09 DG |
167 | } |
168 | ||
d36b8583 | 169 | /* |
0fdd1e2c | 170 | * Adding channel using the lttng API. |
d36b8583 | 171 | */ |
cd80958d | 172 | static int enable_channel(char *session_name) |
d36b8583 | 173 | { |
ae856491 | 174 | int ret = CMD_SUCCESS, warn = 0; |
d36b8583 | 175 | char *channel_name; |
7d29a247 | 176 | struct lttng_domain dom; |
d36b8583 | 177 | |
441c16a7 MD |
178 | memset(&dom, 0, sizeof(dom)); |
179 | ||
d78d6610 | 180 | /* Create lttng domain */ |
7d29a247 DG |
181 | if (opt_kernel) { |
182 | dom.type = LTTNG_DOMAIN_KERNEL; | |
7972aab2 | 183 | dom.buf_type = LTTNG_BUFFER_GLOBAL; |
88c5f0d8 DG |
184 | if (opt_buffer_uid || opt_buffer_pid) { |
185 | ERR("Buffer type not supported for domain -k"); | |
186 | ret = CMD_ERROR; | |
187 | goto error; | |
188 | } | |
d78d6610 | 189 | } else if (opt_userspace) { |
f6a9efaa | 190 | dom.type = LTTNG_DOMAIN_UST; |
7972aab2 DG |
191 | if (opt_buffer_uid) { |
192 | dom.buf_type = LTTNG_BUFFER_PER_UID; | |
193 | } else { | |
88c5f0d8 DG |
194 | if (opt_buffer_global) { |
195 | ERR("Buffer type not supported for domain -u"); | |
196 | ret = CMD_ERROR; | |
197 | goto error; | |
198 | } | |
7972aab2 DG |
199 | dom.buf_type = LTTNG_BUFFER_PER_PID; |
200 | } | |
0fdd1e2c | 201 | } else { |
e14f64a8 | 202 | ERR("Please specify a tracer (-k/--kernel or -u/--userspace)"); |
d16c1a4c | 203 | ret = CMD_ERROR; |
0fdd1e2c | 204 | goto error; |
7d29a247 DG |
205 | } |
206 | ||
5edd7e09 DG |
207 | set_default_attr(&dom); |
208 | ||
1624d5b7 JD |
209 | if ((chan.attr.tracefile_size > 0) && |
210 | (chan.attr.tracefile_size < chan.attr.subbuf_size)) { | |
de65565a | 211 | WARN("Tracefile size rounded up from (%" PRIu64 ") to subbuffer size (%" PRIu64 ")", |
1624d5b7 | 212 | chan.attr.tracefile_size, chan.attr.subbuf_size); |
de65565a | 213 | chan.attr.tracefile_size = chan.attr.subbuf_size; |
1624d5b7 JD |
214 | } |
215 | ||
a79d84dd DG |
216 | /* Setting channel output */ |
217 | if (opt_output) { | |
218 | if (!strncmp(output_mmap, opt_output, strlen(output_mmap))) { | |
219 | chan.attr.output = LTTNG_EVENT_MMAP; | |
220 | } else if (!strncmp(output_splice, opt_output, strlen(output_splice))) { | |
221 | chan.attr.output = LTTNG_EVENT_SPLICE; | |
222 | } else { | |
223 | ERR("Unknown output type %s. Possible values are: %s, %s\n", | |
224 | opt_output, output_mmap, output_splice); | |
225 | usage(stderr); | |
226 | ret = CMD_ERROR; | |
227 | goto error; | |
228 | } | |
229 | } | |
230 | ||
cd80958d DG |
231 | handle = lttng_create_handle(session_name, &dom); |
232 | if (handle == NULL) { | |
233 | ret = -1; | |
234 | goto error; | |
235 | } | |
236 | ||
0fdd1e2c | 237 | /* Strip channel list (format: chan1,chan2,...) */ |
d36b8583 DG |
238 | channel_name = strtok(opt_channels, ","); |
239 | while (channel_name != NULL) { | |
0fdd1e2c DG |
240 | /* Copy channel name and normalize it */ |
241 | strncpy(chan.name, channel_name, NAME_MAX); | |
242 | chan.name[NAME_MAX - 1] = '\0'; | |
243 | ||
244 | DBG("Enabling channel %s", channel_name); | |
245 | ||
246 | ret = lttng_enable_channel(handle, &chan); | |
247 | if (ret < 0) { | |
42224349 | 248 | switch (-ret) { |
f73fabfd DG |
249 | case LTTNG_ERR_KERN_CHAN_EXIST: |
250 | case LTTNG_ERR_UST_CHAN_EXIST: | |
88c5f0d8 | 251 | WARN("Channel %s: %s (session %s)", channel_name, |
42224349 DG |
252 | lttng_strerror(ret), session_name); |
253 | goto error; | |
254 | default: | |
255 | ERR("Channel %s: %s (session %s)", channel_name, | |
256 | lttng_strerror(ret), session_name); | |
257 | break; | |
258 | } | |
ae856491 | 259 | warn = 1; |
d36b8583 | 260 | } else { |
7885e399 DG |
261 | MSG("%s channel %s enabled for session %s", |
262 | opt_kernel ? "Kernel" : "UST", channel_name, | |
263 | session_name); | |
d36b8583 DG |
264 | } |
265 | ||
266 | /* Next event */ | |
267 | channel_name = strtok(NULL, ","); | |
268 | } | |
269 | ||
ae856491 DG |
270 | ret = CMD_SUCCESS; |
271 | ||
d36b8583 | 272 | error: |
ae856491 DG |
273 | if (warn) { |
274 | ret = CMD_WARNING; | |
275 | } | |
276 | ||
cd80958d DG |
277 | lttng_destroy_handle(handle); |
278 | ||
d36b8583 DG |
279 | return ret; |
280 | } | |
281 | ||
282 | /* | |
0fdd1e2c | 283 | * Default value for channel configuration. |
7d29a247 DG |
284 | */ |
285 | static void init_channel_config(void) | |
286 | { | |
5edd7e09 DG |
287 | /* |
288 | * Put -1 everywhere so we can identify those set by the command line and | |
289 | * those needed to be set by the default values. | |
290 | */ | |
291 | memset(&chan.attr, -1, sizeof(chan.attr)); | |
7d29a247 DG |
292 | } |
293 | ||
294 | /* | |
0fdd1e2c | 295 | * Add channel to trace session |
d36b8583 DG |
296 | */ |
297 | int cmd_enable_channels(int argc, const char **argv) | |
298 | { | |
ca1c3607 | 299 | int opt, ret = CMD_SUCCESS; |
d36b8583 | 300 | static poptContext pc; |
cd80958d | 301 | char *session_name = NULL; |
70d0b120 | 302 | char *opt_arg = NULL; |
d36b8583 | 303 | |
7d29a247 DG |
304 | init_channel_config(); |
305 | ||
d36b8583 DG |
306 | pc = poptGetContext(NULL, argc, argv, long_options, 0); |
307 | poptReadDefaultConfig(pc, 0); | |
308 | ||
309 | while ((opt = poptGetNextOpt(pc)) != -1) { | |
310 | switch (opt) { | |
311 | case OPT_HELP: | |
ca1c3607 | 312 | usage(stdout); |
d36b8583 | 313 | goto end; |
7d29a247 DG |
314 | case OPT_DISCARD: |
315 | chan.attr.overwrite = 0; | |
316 | DBG("Channel set to discard"); | |
317 | break; | |
318 | case OPT_OVERWRITE: | |
319 | chan.attr.overwrite = 1; | |
320 | DBG("Channel set to overwrite"); | |
321 | break; | |
322 | case OPT_SUBBUF_SIZE: | |
1cb514ce MD |
323 | { |
324 | uint64_t rounded_size; | |
325 | int order; | |
326 | ||
70d0b120 SM |
327 | /* Parse the size */ |
328 | opt_arg = poptGetOptArg(pc); | |
1cb514ce MD |
329 | if (utils_parse_size_suffix(opt_arg, &chan.attr.subbuf_size) < 0 || !chan.attr.subbuf_size) { |
330 | ERR("Wrong value in --subbuf-size parameter: %s", opt_arg); | |
70d0b120 SM |
331 | ret = CMD_ERROR; |
332 | goto end; | |
333 | } | |
334 | ||
1cb514ce MD |
335 | order = get_count_order_u64(chan.attr.subbuf_size); |
336 | assert(order >= 0); | |
337 | rounded_size = 1ULL << order; | |
338 | if (rounded_size != chan.attr.subbuf_size) { | |
339 | WARN("The subbuf size (%" PRIu64 ") is rounded to the next power of 2 (%" PRIu64 ")", | |
340 | chan.attr.subbuf_size, rounded_size); | |
341 | chan.attr.subbuf_size = rounded_size; | |
70d0b120 SM |
342 | } |
343 | ||
1cb514ce MD |
344 | /* Should now be power of 2 */ |
345 | assert(!((chan.attr.subbuf_size - 1) & chan.attr.subbuf_size)); | |
346 | ||
5a0de755 | 347 | DBG("Channel subbuf size set to %" PRIu64, chan.attr.subbuf_size); |
7d29a247 | 348 | break; |
1cb514ce | 349 | } |
7d29a247 | 350 | case OPT_NUM_SUBBUF: |
1cb514ce MD |
351 | { |
352 | uint64_t rounded_size; | |
353 | int order; | |
354 | ||
16068db5 | 355 | errno = 0; |
1cb514ce MD |
356 | opt_arg = poptGetOptArg(pc); |
357 | chan.attr.num_subbuf = strtoull(opt_arg, NULL, 0); | |
358 | if (errno != 0 || !chan.attr.num_subbuf || !isdigit(opt_arg[0])) { | |
359 | ERR("Wrong value in --num-subbuf parameter: %s", opt_arg); | |
16068db5 MD |
360 | ret = CMD_ERROR; |
361 | goto end; | |
362 | } | |
363 | ||
1cb514ce MD |
364 | order = get_count_order_u64(chan.attr.num_subbuf); |
365 | assert(order >= 0); | |
366 | rounded_size = 1ULL << order; | |
367 | if (rounded_size != chan.attr.num_subbuf) { | |
368 | WARN("The number of subbuffers (%" PRIu64 ") is rounded to the next power of 2 (%" PRIu64 ")", | |
369 | chan.attr.num_subbuf, rounded_size); | |
370 | chan.attr.num_subbuf = rounded_size; | |
371 | } | |
372 | ||
373 | /* Should now be power of 2 */ | |
374 | assert(!((chan.attr.num_subbuf - 1) & chan.attr.num_subbuf)); | |
375 | ||
5a0de755 | 376 | DBG("Channel subbuf num set to %" PRIu64, chan.attr.num_subbuf); |
7d29a247 | 377 | break; |
1cb514ce | 378 | } |
7d29a247 | 379 | case OPT_SWITCH_TIMER: |
16068db5 MD |
380 | { |
381 | unsigned long v; | |
382 | ||
383 | errno = 0; | |
1cb514ce MD |
384 | opt_arg = poptGetOptArg(pc); |
385 | v = strtoul(opt_arg, NULL, 0); | |
386 | if (errno != 0 || !isdigit(opt_arg[0])) { | |
387 | ERR("Wrong value in --switch-timer parameter: %s", opt_arg); | |
16068db5 MD |
388 | ret = CMD_ERROR; |
389 | goto end; | |
390 | } | |
391 | if (v != (uint32_t) v) { | |
392 | ERR("32-bit overflow in --switch-timer parameter: %s", opt_arg); | |
393 | ret = CMD_ERROR; | |
394 | goto end; | |
395 | } | |
396 | chan.attr.switch_timer_interval = (uint32_t) v; | |
7d29a247 DG |
397 | DBG("Channel switch timer interval set to %d", chan.attr.switch_timer_interval); |
398 | break; | |
16068db5 | 399 | } |
7d29a247 | 400 | case OPT_READ_TIMER: |
16068db5 MD |
401 | { |
402 | unsigned long v; | |
403 | ||
404 | errno = 0; | |
1cb514ce MD |
405 | opt_arg = poptGetOptArg(pc); |
406 | v = strtoul(opt_arg, NULL, 0); | |
407 | if (errno != 0 || !isdigit(opt_arg[0])) { | |
408 | ERR("Wrong value in --read-timer parameter: %s", opt_arg); | |
16068db5 MD |
409 | ret = CMD_ERROR; |
410 | goto end; | |
411 | } | |
412 | if (v != (uint32_t) v) { | |
413 | ERR("32-bit overflow in --read-timer parameter: %s", opt_arg); | |
414 | ret = CMD_ERROR; | |
415 | goto end; | |
416 | } | |
417 | chan.attr.read_timer_interval = (uint32_t) v; | |
7d29a247 | 418 | DBG("Channel read timer interval set to %d", chan.attr.read_timer_interval); |
d36b8583 | 419 | break; |
16068db5 | 420 | } |
eeac7d46 MD |
421 | case OPT_USERSPACE: |
422 | opt_userspace = 1; | |
eeac7d46 | 423 | break; |
1624d5b7 | 424 | case OPT_TRACEFILE_SIZE: |
1cb514ce | 425 | opt_arg = poptGetOptArg(pc); |
16068db5 | 426 | if (utils_parse_size_suffix(opt_arg, &chan.attr.tracefile_size) < 0) { |
1cb514ce | 427 | ERR("Wrong value in --tracefile-size parameter: %s", opt_arg); |
16068db5 MD |
428 | ret = CMD_ERROR; |
429 | goto end; | |
430 | } | |
1624d5b7 JD |
431 | DBG("Maximum tracefile size set to %" PRIu64, |
432 | chan.attr.tracefile_size); | |
433 | break; | |
434 | case OPT_TRACEFILE_COUNT: | |
16068db5 MD |
435 | { |
436 | unsigned long v; | |
437 | ||
438 | errno = 0; | |
1cb514ce MD |
439 | opt_arg = poptGetOptArg(pc); |
440 | v = strtoul(opt_arg, NULL, 0); | |
441 | if (errno != 0 || !isdigit(opt_arg[0])) { | |
442 | ERR("Wrong value in --tracefile-count parameter: %s", opt_arg); | |
16068db5 MD |
443 | ret = CMD_ERROR; |
444 | goto end; | |
445 | } | |
446 | if (v != (uint32_t) v) { | |
447 | ERR("32-bit overflow in --tracefile-count parameter: %s", opt_arg); | |
448 | ret = CMD_ERROR; | |
449 | goto end; | |
450 | } | |
451 | chan.attr.tracefile_count = (uint32_t) v; | |
1624d5b7 JD |
452 | DBG("Maximum tracefile count set to %" PRIu64, |
453 | chan.attr.tracefile_count); | |
454 | break; | |
16068db5 | 455 | } |
679b4943 SM |
456 | case OPT_LIST_OPTIONS: |
457 | list_cmd_options(stdout, long_options); | |
679b4943 | 458 | goto end; |
d36b8583 DG |
459 | default: |
460 | usage(stderr); | |
461 | ret = CMD_UNDEFINED; | |
462 | goto end; | |
463 | } | |
464 | } | |
465 | ||
466 | opt_channels = (char*) poptGetArg(pc); | |
467 | if (opt_channels == NULL) { | |
7d29a247 | 468 | ERR("Missing channel name.\n"); |
d36b8583 | 469 | usage(stderr); |
ca1c3607 | 470 | ret = CMD_ERROR; |
d36b8583 DG |
471 | goto end; |
472 | } | |
473 | ||
cd80958d DG |
474 | if (!opt_session_name) { |
475 | session_name = get_session_name(); | |
476 | if (session_name == NULL) { | |
ca1c3607 | 477 | ret = CMD_ERROR; |
cd80958d DG |
478 | goto end; |
479 | } | |
480 | } else { | |
481 | session_name = opt_session_name; | |
482 | } | |
483 | ||
484 | ret = enable_channel(session_name); | |
d36b8583 DG |
485 | |
486 | end: | |
5853fd43 DG |
487 | if (!opt_session_name && session_name) { |
488 | free(session_name); | |
489 | } | |
ca1c3607 | 490 | poptFreeContext(pc); |
d36b8583 DG |
491 | return ret; |
492 | } |