Move utils_expand_path and utils_expand_path_keep_symlink to libpath.la
[lttng-tools.git] / src / bin / lttng / commands / enable_channels.cpp
1 /*
2 * Copyright (C) 2011 EfficiOS Inc.
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8 #define _LGPL_SOURCE
9 #include <popt.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <sys/stat.h>
14 #include <sys/types.h>
15 #include <unistd.h>
16 #include <inttypes.h>
17 #include <ctype.h>
18
19 #include <common/sessiond-comm/sessiond-comm.h>
20 #include <common/utils.h>
21 #include <common/mi-lttng.h>
22
23 #include <lttng/domain-internal.h>
24
25 #include "../command.h"
26 #include "../utils.h"
27
28
29 static struct lttng_channel chan_opts;
30 static char *opt_channels;
31 static int opt_kernel;
32 static char *opt_session_name;
33 static int opt_userspace;
34 static char *opt_output;
35 static int opt_buffer_uid;
36 static int opt_buffer_pid;
37 static int opt_buffer_global;
38 static struct {
39 bool set;
40 uint64_t interval;
41 } opt_monitor_timer;
42 static struct {
43 bool set;
44 int64_t value;
45 } opt_blocking_timeout;
46
47 static struct mi_writer *writer;
48
49 #ifdef LTTNG_EMBED_HELP
50 static const char help_msg[] =
51 #include <lttng-enable-channel.1.h>
52 ;
53 #endif
54
55 enum {
56 OPT_HELP = 1,
57 OPT_DISCARD,
58 OPT_OVERWRITE,
59 OPT_SUBBUF_SIZE,
60 OPT_NUM_SUBBUF,
61 OPT_SWITCH_TIMER,
62 OPT_MONITOR_TIMER,
63 OPT_READ_TIMER,
64 OPT_USERSPACE,
65 OPT_LIST_OPTIONS,
66 OPT_TRACEFILE_SIZE,
67 OPT_TRACEFILE_COUNT,
68 OPT_BLOCKING_TIMEOUT,
69 };
70
71 static struct lttng_handle *handle;
72
73 const char *output_mmap = "mmap";
74 const char *output_splice = "splice";
75
76 static struct poptOption long_options[] = {
77 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
78 {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
79 {"session", 's', POPT_ARG_STRING, &opt_session_name, 0, 0, 0},
80 {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
81 {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0},
82 {"discard", 0, POPT_ARG_NONE, 0, OPT_DISCARD, 0, 0},
83 {"overwrite", 0, POPT_ARG_NONE, 0, OPT_OVERWRITE, 0, 0},
84 {"subbuf-size", 0, POPT_ARG_STRING, 0, OPT_SUBBUF_SIZE, 0, 0},
85 {"num-subbuf", 0, POPT_ARG_INT, 0, OPT_NUM_SUBBUF, 0, 0},
86 {"switch-timer", 0, POPT_ARG_INT, 0, OPT_SWITCH_TIMER, 0, 0},
87 {"monitor-timer", 0, POPT_ARG_INT, 0, OPT_MONITOR_TIMER, 0, 0},
88 {"read-timer", 0, POPT_ARG_INT, 0, OPT_READ_TIMER, 0, 0},
89 {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
90 {"output", 0, POPT_ARG_STRING, &opt_output, 0, 0, 0},
91 {"buffers-uid", 0, POPT_ARG_VAL, &opt_buffer_uid, 1, 0, 0},
92 {"buffers-pid", 0, POPT_ARG_VAL, &opt_buffer_pid, 1, 0, 0},
93 {"buffers-global", 0, POPT_ARG_VAL, &opt_buffer_global, 1, 0, 0},
94 {"tracefile-size", 'C', POPT_ARG_INT, 0, OPT_TRACEFILE_SIZE, 0, 0},
95 {"tracefile-count", 'W', POPT_ARG_INT, 0, OPT_TRACEFILE_COUNT, 0, 0},
96 {"blocking-timeout", 0, POPT_ARG_INT, 0, OPT_BLOCKING_TIMEOUT, 0, 0},
97 {0, 0, 0, 0, 0, 0, 0}
98 };
99
100 /*
101 * Set default attributes depending on those already defined from the command
102 * line.
103 */
104 static void set_default_attr(struct lttng_domain *dom)
105 {
106 struct lttng_channel_attr default_attr;
107
108 memset(&default_attr, 0, sizeof(default_attr));
109
110 /* Set attributes */
111 lttng_channel_set_default_attr(dom, &default_attr);
112
113 if (chan_opts.attr.overwrite == -1) {
114 chan_opts.attr.overwrite = default_attr.overwrite;
115 }
116 if (chan_opts.attr.subbuf_size == -1) {
117 chan_opts.attr.subbuf_size = default_attr.subbuf_size;
118 }
119 if (chan_opts.attr.num_subbuf == -1) {
120 chan_opts.attr.num_subbuf = default_attr.num_subbuf;
121 }
122 if (chan_opts.attr.switch_timer_interval == -1) {
123 chan_opts.attr.switch_timer_interval = default_attr.switch_timer_interval;
124 }
125 if (chan_opts.attr.read_timer_interval == -1) {
126 chan_opts.attr.read_timer_interval = default_attr.read_timer_interval;
127 }
128 if ((int) chan_opts.attr.output == -1) {
129 chan_opts.attr.output = default_attr.output;
130 }
131 if (chan_opts.attr.tracefile_count == -1) {
132 chan_opts.attr.tracefile_count = default_attr.tracefile_count;
133 }
134 if (chan_opts.attr.tracefile_size == -1) {
135 chan_opts.attr.tracefile_size = default_attr.tracefile_size;
136 }
137 }
138
139 /*
140 * Adding channel using the lttng API.
141 */
142 static int enable_channel(char *session_name)
143 {
144 struct lttng_channel *channel = NULL;
145 int ret = CMD_SUCCESS, warn = 0, error = 0, success = 0;
146 char *channel_name;
147 struct lttng_domain dom;
148
149 memset(&dom, 0, sizeof(dom));
150
151 /* Validate options. */
152 if (opt_kernel) {
153 if (opt_blocking_timeout.set) {
154 ERR("Retry timeout option not supported for kernel domain (-k)");
155 ret = CMD_ERROR;
156 goto error;
157 }
158 }
159
160 /* Create lttng domain */
161 if (opt_kernel) {
162 dom.type = LTTNG_DOMAIN_KERNEL;
163 dom.buf_type = LTTNG_BUFFER_GLOBAL;
164 if (opt_buffer_uid || opt_buffer_pid) {
165 ERR("Buffer type not supported for domain -k");
166 ret = CMD_ERROR;
167 goto error;
168 }
169 } else if (opt_userspace) {
170 dom.type = LTTNG_DOMAIN_UST;
171 if (opt_buffer_pid) {
172 dom.buf_type = LTTNG_BUFFER_PER_PID;
173 } else {
174 if (opt_buffer_global) {
175 ERR("Buffer type not supported for domain -u");
176 ret = CMD_ERROR;
177 goto error;
178 }
179 dom.buf_type = LTTNG_BUFFER_PER_UID;
180 }
181 } else {
182 /* Checked by the caller. */
183 abort();
184 }
185
186 set_default_attr(&dom);
187
188 if (chan_opts.attr.tracefile_size == 0 && chan_opts.attr.tracefile_count) {
189 ERR("Missing option --tracefile-size. "
190 "A file count without a size won't do anything.");
191 ret = CMD_ERROR;
192 goto error;
193 }
194
195 if ((chan_opts.attr.tracefile_size > 0) &&
196 (chan_opts.attr.tracefile_size < chan_opts.attr.subbuf_size)) {
197 WARN("Tracefile size rounded up from (%" PRIu64 ") to subbuffer size (%" PRIu64 ")",
198 chan_opts.attr.tracefile_size, chan_opts.attr.subbuf_size);
199 chan_opts.attr.tracefile_size = chan_opts.attr.subbuf_size;
200 }
201
202 /* Setting channel output */
203 if (opt_output) {
204 if (!strncmp(output_mmap, opt_output, strlen(output_mmap))) {
205 chan_opts.attr.output = LTTNG_EVENT_MMAP;
206 } else if (!strncmp(output_splice, opt_output, strlen(output_splice))) {
207 chan_opts.attr.output = LTTNG_EVENT_SPLICE;
208 } else {
209 ERR("Unknown output type %s. Possible values are: %s, %s\n",
210 opt_output, output_mmap, output_splice);
211 ret = CMD_ERROR;
212 goto error;
213 }
214 }
215
216 handle = lttng_create_handle(session_name, &dom);
217 if (handle == NULL) {
218 ret = -1;
219 goto error;
220 }
221
222 /* Mi open channels element */
223 if (lttng_opt_mi) {
224 LTTNG_ASSERT(writer);
225 ret = mi_lttng_channels_open(writer);
226 if (ret) {
227 ret = CMD_ERROR;
228 goto error;
229 }
230 }
231
232 /* Strip channel list (format: chan1,chan2,...) */
233 channel_name = strtok(opt_channels, ",");
234 while (channel_name != NULL) {
235 void *extended_ptr;
236
237 /* Validate channel name's length */
238 if (strlen(channel_name) >= sizeof(chan_opts.name)) {
239 ERR("Channel name is too long (max. %zu characters)",
240 sizeof(chan_opts.name) - 1);
241 error = 1;
242 goto skip_enable;
243 }
244
245 /*
246 * A dynamically-allocated channel is used in order to allow
247 * the configuration of extended attributes (post-2.9).
248 */
249 channel = lttng_channel_create(&dom);
250 if (!channel) {
251 ERR("Unable to create channel object");
252 error = 1;
253 goto error;
254 }
255
256 /* Copy channel name */
257 strcpy(channel->name, channel_name);
258 channel->enabled = 1;
259 extended_ptr = channel->attr.extended.ptr;
260 memcpy(&channel->attr, &chan_opts.attr, sizeof(chan_opts.attr));
261 channel->attr.extended.ptr = extended_ptr;
262 if (opt_monitor_timer.set) {
263 ret = lttng_channel_set_monitor_timer_interval(channel,
264 opt_monitor_timer.interval);
265 if (ret) {
266 ERR("Failed to set the channel's monitor timer interval");
267 error = 1;
268 goto error;
269 }
270 }
271 if (opt_blocking_timeout.set) {
272 ret = lttng_channel_set_blocking_timeout(channel,
273 opt_blocking_timeout.value);
274 if (ret) {
275 ERR("Failed to set the channel's blocking timeout");
276 error = 1;
277 goto error;
278 }
279 }
280
281 DBG("Enabling channel %s", channel_name);
282
283 ret = lttng_enable_channel(handle, channel);
284 if (ret < 0) {
285 success = 0;
286 switch (-ret) {
287 case LTTNG_ERR_KERN_CHAN_EXIST:
288 case LTTNG_ERR_UST_CHAN_EXIST:
289 case LTTNG_ERR_CHAN_EXIST:
290 WARN("Channel %s: %s (session %s)", channel_name,
291 lttng_strerror(ret), session_name);
292 warn = 1;
293 break;
294 case LTTNG_ERR_INVALID_CHANNEL_NAME:
295 ERR("Invalid channel name: \"%s\". "
296 "Channel names may not start with '.', and "
297 "may not contain '/'.", channel_name);
298 error = 1;
299 break;
300 default:
301 ERR("Channel %s: %s (session %s)", channel_name,
302 lttng_strerror(ret), session_name);
303 error = 1;
304 break;
305 }
306 } else {
307 MSG("%s channel %s enabled for session %s",
308 lttng_domain_type_str(dom.type),
309 channel_name, session_name);
310 success = 1;
311 }
312
313 skip_enable:
314 if (lttng_opt_mi) {
315 /* Mi print the channel element and leave it open */
316 ret = mi_lttng_channel(writer, channel, 1);
317 if (ret) {
318 ret = CMD_ERROR;
319 goto error;
320 }
321
322 /* Individual Success ? */
323 ret = mi_lttng_writer_write_element_bool(writer,
324 mi_lttng_element_command_success, success);
325 if (ret) {
326 ret = CMD_ERROR;
327 goto error;
328 }
329
330 /* Close channel element */
331 ret = mi_lttng_writer_close_element(writer);
332 if (ret) {
333 ret = CMD_ERROR;
334 goto error;
335 }
336 }
337
338 /* Next channel */
339 channel_name = strtok(NULL, ",");
340 lttng_channel_destroy(channel);
341 channel = NULL;
342 }
343
344 if (lttng_opt_mi) {
345 /* Close channels element */
346 ret = mi_lttng_writer_close_element(writer);
347 if (ret) {
348 ret = CMD_ERROR;
349 goto error;
350 }
351 }
352
353 ret = CMD_SUCCESS;
354
355 error:
356 if (channel) {
357 lttng_channel_destroy(channel);
358 }
359 /* If more important error happen bypass the warning */
360 if (!ret && warn) {
361 ret = CMD_WARNING;
362 }
363 /* If more important error happen bypass the warning */
364 if (!ret && error) {
365 ret = CMD_ERROR;
366 }
367
368 lttng_destroy_handle(handle);
369
370 return ret;
371 }
372
373 /*
374 * Default value for channel configuration.
375 */
376 static void init_channel_config(void)
377 {
378 /*
379 * Put -1 everywhere so we can identify those set by the command line and
380 * those needed to be set by the default values.
381 */
382 memset(&chan_opts.attr, -1, sizeof(chan_opts.attr));
383 chan_opts.attr.extended.ptr = NULL;
384 }
385
386 /*
387 * Add channel to trace session
388 */
389 int cmd_enable_channels(int argc, const char **argv)
390 {
391 int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1;
392 static poptContext pc;
393 char *session_name = NULL;
394 char *opt_arg = NULL;
395 const char *leftover = NULL;
396
397 init_channel_config();
398
399 pc = poptGetContext(NULL, argc, argv, long_options, 0);
400 poptReadDefaultConfig(pc, 0);
401
402 while ((opt = poptGetNextOpt(pc)) != -1) {
403 switch (opt) {
404 case OPT_HELP:
405 SHOW_HELP();
406 goto end;
407 case OPT_DISCARD:
408 chan_opts.attr.overwrite = 0;
409 DBG("Channel set to discard");
410 break;
411 case OPT_OVERWRITE:
412 chan_opts.attr.overwrite = 1;
413 DBG("Channel set to overwrite");
414 break;
415 case OPT_SUBBUF_SIZE:
416 {
417 uint64_t rounded_size;
418 int order;
419
420 /* Parse the size */
421 opt_arg = poptGetOptArg(pc);
422 if (utils_parse_size_suffix(opt_arg, &chan_opts.attr.subbuf_size) < 0 || !chan_opts.attr.subbuf_size) {
423 ERR("Wrong value in --subbuf-size parameter: %s", opt_arg);
424 ret = CMD_ERROR;
425 goto end;
426 }
427
428 order = get_count_order_u64(chan_opts.attr.subbuf_size);
429 LTTNG_ASSERT(order >= 0);
430 rounded_size = 1ULL << order;
431 if (rounded_size < chan_opts.attr.subbuf_size) {
432 ERR("The subbuf size (%" PRIu64 ") is rounded and overflows!",
433 chan_opts.attr.subbuf_size);
434 ret = CMD_ERROR;
435 goto end;
436 }
437
438 if (rounded_size != chan_opts.attr.subbuf_size) {
439 WARN("The subbuf size (%" PRIu64 ") is rounded to the next power of 2 (%" PRIu64 ")",
440 chan_opts.attr.subbuf_size, rounded_size);
441 chan_opts.attr.subbuf_size = rounded_size;
442 }
443
444 /* Should now be power of 2 */
445 LTTNG_ASSERT(!((chan_opts.attr.subbuf_size - 1) & chan_opts.attr.subbuf_size));
446
447 DBG("Channel subbuf size set to %" PRIu64, chan_opts.attr.subbuf_size);
448 break;
449 }
450 case OPT_NUM_SUBBUF:
451 {
452 uint64_t rounded_size;
453 int order;
454
455 errno = 0;
456 opt_arg = poptGetOptArg(pc);
457 chan_opts.attr.num_subbuf = strtoull(opt_arg, NULL, 0);
458 if (errno != 0 || !chan_opts.attr.num_subbuf || !isdigit(opt_arg[0])) {
459 ERR("Wrong value in --num-subbuf parameter: %s", opt_arg);
460 ret = CMD_ERROR;
461 goto end;
462 }
463
464 order = get_count_order_u64(chan_opts.attr.num_subbuf);
465 LTTNG_ASSERT(order >= 0);
466 rounded_size = 1ULL << order;
467 if (rounded_size < chan_opts.attr.num_subbuf) {
468 ERR("The number of subbuffers (%" PRIu64 ") is rounded and overflows!",
469 chan_opts.attr.num_subbuf);
470 ret = CMD_ERROR;
471 goto end;
472 }
473
474 if (rounded_size != chan_opts.attr.num_subbuf) {
475 WARN("The number of subbuffers (%" PRIu64 ") is rounded to the next power of 2 (%" PRIu64 ")",
476 chan_opts.attr.num_subbuf, rounded_size);
477 chan_opts.attr.num_subbuf = rounded_size;
478 }
479
480 /* Should now be power of 2 */
481 LTTNG_ASSERT(!((chan_opts.attr.num_subbuf - 1) & chan_opts.attr.num_subbuf));
482
483 DBG("Channel subbuf num set to %" PRIu64, chan_opts.attr.num_subbuf);
484 break;
485 }
486 case OPT_SWITCH_TIMER:
487 {
488 uint64_t v;
489
490 errno = 0;
491 opt_arg = poptGetOptArg(pc);
492
493 if (utils_parse_time_suffix(opt_arg, &v) < 0) {
494 ERR("Wrong value for --switch-timer parameter: %s", opt_arg);
495 ret = CMD_ERROR;
496 goto end;
497 }
498
499 if (v != (uint32_t) v) {
500 ERR("32-bit overflow in --switch-timer parameter: %s", opt_arg);
501 ret = CMD_ERROR;
502 goto end;
503 }
504 chan_opts.attr.switch_timer_interval = (uint32_t) v;
505 DBG("Channel switch timer interval set to %d %s",
506 chan_opts.attr.switch_timer_interval,
507 USEC_UNIT);
508 break;
509 }
510 case OPT_READ_TIMER:
511 {
512 uint64_t v;
513
514 errno = 0;
515 opt_arg = poptGetOptArg(pc);
516
517 if (utils_parse_time_suffix(opt_arg, &v) < 0) {
518 ERR("Wrong value for --read-timer parameter: %s", opt_arg);
519 ret = CMD_ERROR;
520 goto end;
521 }
522
523 if (v != (uint32_t) v) {
524 ERR("32-bit overflow in --read-timer parameter: %s", opt_arg);
525 ret = CMD_ERROR;
526 goto end;
527 }
528 chan_opts.attr.read_timer_interval = (uint32_t) v;
529 DBG("Channel read timer interval set to %d %s",
530 chan_opts.attr.read_timer_interval,
531 USEC_UNIT);
532 break;
533 }
534 case OPT_MONITOR_TIMER:
535 {
536 uint64_t v;
537
538 errno = 0;
539 opt_arg = poptGetOptArg(pc);
540
541 if (utils_parse_time_suffix(opt_arg, &v) < 0) {
542 ERR("Wrong value for --monitor-timer parameter: %s", opt_arg);
543 ret = CMD_ERROR;
544 goto end;
545 }
546 opt_monitor_timer.interval = (uint64_t) v;
547 opt_monitor_timer.set = true;
548 DBG("Channel monitor timer interval set to %" PRIu64 " %s",
549 opt_monitor_timer.interval,
550 USEC_UNIT);
551 break;
552 }
553 case OPT_BLOCKING_TIMEOUT:
554 {
555 uint64_t v;
556 long long v_msec;
557
558 errno = 0;
559 opt_arg = poptGetOptArg(pc);
560
561 if (strcmp(opt_arg, "inf") == 0) {
562 opt_blocking_timeout.value = (int64_t) -1;
563 opt_blocking_timeout.set = true;
564 DBG("Channel blocking timeout set to infinity");
565 break;
566 }
567
568 if (utils_parse_time_suffix(opt_arg, &v) < 0) {
569 ERR("Wrong value for --blocking-timeout parameter: %s", opt_arg);
570 ret = CMD_ERROR;
571 goto end;
572 }
573
574 /*
575 * While LTTng-UST and LTTng-tools will accept a
576 * blocking timeout expressed in µs, the current
577 * tracer implementation relies on poll() which
578 * takes an "int timeout" parameter expressed in
579 * msec.
580 *
581 * Since the error reporting from the tracer is
582 * not precise, we perform this check here to
583 * provide a helpful error message in case of
584 * overflow.
585 *
586 * The setter (liblttng-ctl) also performs an
587 * equivalent check.
588 */
589 v_msec = v / 1000;
590 if (v_msec != (int32_t) v_msec) {
591 ERR("32-bit milliseconds overflow in --blocking-timeout parameter: %s", opt_arg);
592 ret = CMD_ERROR;
593 goto end;
594 }
595
596 opt_blocking_timeout.value = (int64_t) v;
597 opt_blocking_timeout.set = true;
598 DBG("Channel blocking timeout set to %" PRId64 " %s%s",
599 opt_blocking_timeout.value,
600 USEC_UNIT,
601 opt_blocking_timeout.value == 0 ?
602 " (non-blocking)" : "");
603 break;
604 }
605 case OPT_USERSPACE:
606 opt_userspace = 1;
607 break;
608 case OPT_TRACEFILE_SIZE:
609 opt_arg = poptGetOptArg(pc);
610 if (utils_parse_size_suffix(opt_arg, &chan_opts.attr.tracefile_size) < 0) {
611 ERR("Wrong value in --tracefile-size parameter: %s", opt_arg);
612 ret = CMD_ERROR;
613 goto end;
614 }
615 DBG("Maximum tracefile size set to %" PRIu64,
616 chan_opts.attr.tracefile_size);
617 break;
618 case OPT_TRACEFILE_COUNT:
619 {
620 unsigned long v;
621
622 errno = 0;
623 opt_arg = poptGetOptArg(pc);
624 v = strtoul(opt_arg, NULL, 0);
625 if (errno != 0 || !isdigit(opt_arg[0])) {
626 ERR("Wrong value in --tracefile-count parameter: %s", opt_arg);
627 ret = CMD_ERROR;
628 goto end;
629 }
630 if (v != (uint32_t) v) {
631 ERR("32-bit overflow in --tracefile-count parameter: %s", opt_arg);
632 ret = CMD_ERROR;
633 goto end;
634 }
635 chan_opts.attr.tracefile_count = (uint32_t) v;
636 DBG("Maximum tracefile count set to %" PRIu64,
637 chan_opts.attr.tracefile_count);
638 break;
639 }
640 case OPT_LIST_OPTIONS:
641 list_cmd_options(stdout, long_options);
642 goto end;
643 default:
644 ret = CMD_UNDEFINED;
645 goto end;
646 }
647 }
648
649 ret = print_missing_or_multiple_domains(
650 opt_kernel + opt_userspace, false);
651 if (ret) {
652 ret = CMD_ERROR;
653 goto end;
654 }
655
656 if (chan_opts.attr.overwrite == 1 && opt_blocking_timeout.set &&
657 opt_blocking_timeout.value != 0) {
658 ERR("You cannot specify --overwrite and --blocking-timeout=N, "
659 "where N is different than 0");
660 ret = CMD_ERROR;
661 goto end;
662 }
663
664 /* Mi check */
665 if (lttng_opt_mi) {
666 writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi);
667 if (!writer) {
668 ret = -LTTNG_ERR_NOMEM;
669 goto end;
670 }
671
672 /* Open command element */
673 ret = mi_lttng_writer_command_open(writer,
674 mi_lttng_element_command_enable_channels);
675 if (ret) {
676 ret = CMD_ERROR;
677 goto end;
678 }
679
680 /* Open output element */
681 ret = mi_lttng_writer_open_element(writer,
682 mi_lttng_element_command_output);
683 if (ret) {
684 ret = CMD_ERROR;
685 goto end;
686 }
687 }
688
689 opt_channels = (char*) poptGetArg(pc);
690 if (opt_channels == NULL) {
691 ERR("Missing channel name.\n");
692 ret = CMD_ERROR;
693 success = 0;
694 goto mi_closing;
695 }
696
697 leftover = poptGetArg(pc);
698 if (leftover) {
699 ERR("Unknown argument: %s", leftover);
700 ret = CMD_ERROR;
701 success = 0;
702 goto mi_closing;
703 }
704
705 if (!opt_session_name) {
706 session_name = get_session_name();
707 if (session_name == NULL) {
708 command_ret = CMD_ERROR;
709 success = 0;
710 goto mi_closing;
711 }
712 } else {
713 session_name = opt_session_name;
714 }
715
716 command_ret = enable_channel(session_name);
717 if (command_ret) {
718 success = 0;
719 }
720
721 mi_closing:
722 /* Mi closing */
723 if (lttng_opt_mi) {
724 /* Close output element */
725 ret = mi_lttng_writer_close_element(writer);
726 if (ret) {
727 goto end;
728 }
729
730 /* Success ? */
731 ret = mi_lttng_writer_write_element_bool(writer,
732 mi_lttng_element_command_success, success);
733 if (ret) {
734 goto end;
735 }
736
737 /* Command element close */
738 ret = mi_lttng_writer_command_close(writer);
739 if (ret) {
740 goto end;
741 }
742 }
743
744 end:
745 /* Mi clean-up */
746 if (writer && mi_lttng_writer_destroy(writer)) {
747 /* Preserve original error code */
748 ret = ret ? ret : LTTNG_ERR_MI_IO_FAIL;
749 }
750
751 if (!opt_session_name && session_name) {
752 free(session_name);
753 }
754
755 /* Overwrite ret if an error occurred when enable_channel */
756 ret = command_ret ? command_ret : ret;
757 poptFreeContext(pc);
758 return ret;
759 }
This page took 0.110855 seconds and 4 git commands to generate.