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