Fix: define _LGPL_SOURCE in C files
[lttng-tools.git] / src / bin / lttng / commands / enable_channels.c
1 /*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 *
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.
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 *
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.
16 */
17
18 #define _GNU_SOURCE
19 #define _LGPL_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 #include <inttypes.h>
28 #include <assert.h>
29 #include <ctype.h>
30
31 #include <common/sessiond-comm/sessiond-comm.h>
32 #include <common/utils.h>
33 #include <common/mi-lttng.h>
34
35 #include "../command.h"
36 #include "../utils.h"
37
38
39 static char *opt_channels;
40 static int opt_kernel;
41 static char *opt_session_name;
42 static int opt_userspace;
43 static struct lttng_channel chan;
44 static char *opt_output;
45 static int opt_buffer_uid;
46 static int opt_buffer_pid;
47 static int opt_buffer_global;
48
49 static struct mi_writer *writer;
50
51 enum {
52 OPT_HELP = 1,
53 OPT_DISCARD,
54 OPT_OVERWRITE,
55 OPT_SUBBUF_SIZE,
56 OPT_NUM_SUBBUF,
57 OPT_SWITCH_TIMER,
58 OPT_READ_TIMER,
59 OPT_USERSPACE,
60 OPT_LIST_OPTIONS,
61 OPT_TRACEFILE_SIZE,
62 OPT_TRACEFILE_COUNT,
63 };
64
65 static struct lttng_handle *handle;
66
67 const char *output_mmap = "mmap";
68 const char *output_splice = "splice";
69
70 static struct poptOption long_options[] = {
71 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
72 {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
73 {"session", 's', POPT_ARG_STRING, &opt_session_name, 0, 0, 0},
74 {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
75 {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0},
76 {"discard", 0, POPT_ARG_NONE, 0, OPT_DISCARD, 0, 0},
77 {"overwrite", 0, POPT_ARG_NONE, 0, OPT_OVERWRITE, 0, 0},
78 {"subbuf-size", 0, POPT_ARG_STRING, 0, OPT_SUBBUF_SIZE, 0, 0},
79 {"num-subbuf", 0, POPT_ARG_INT, 0, OPT_NUM_SUBBUF, 0, 0},
80 {"switch-timer", 0, POPT_ARG_INT, 0, OPT_SWITCH_TIMER, 0, 0},
81 {"read-timer", 0, POPT_ARG_INT, 0, OPT_READ_TIMER, 0, 0},
82 {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
83 {"output", 0, POPT_ARG_STRING, &opt_output, 0, 0, 0},
84 {"buffers-uid", 0, POPT_ARG_VAL, &opt_buffer_uid, 1, 0, 0},
85 {"buffers-pid", 0, POPT_ARG_VAL, &opt_buffer_pid, 1, 0, 0},
86 {"buffers-global", 0, POPT_ARG_VAL, &opt_buffer_global, 1, 0, 0},
87 {"tracefile-size", 'C', POPT_ARG_INT, 0, OPT_TRACEFILE_SIZE, 0, 0},
88 {"tracefile-count", 'W', POPT_ARG_INT, 0, OPT_TRACEFILE_COUNT, 0, 0},
89 {0, 0, 0, 0, 0, 0, 0}
90 };
91
92 /*
93 * usage
94 */
95 static void usage(FILE *ofp)
96 {
97 fprintf(ofp, "usage: lttng enable-channel NAME[,NAME2,...] (-u | -k) [OPTIONS]\n");
98 fprintf(ofp, "\n");
99 fprintf(ofp, "Options:\n");
100 fprintf(ofp, " -h, --help Show this help\n");
101 fprintf(ofp, " --list-options Simple listing of options\n");
102 fprintf(ofp, " -s, --session NAME Apply to session name\n");
103 fprintf(ofp, " -k, --kernel Apply to the kernel tracer\n");
104 fprintf(ofp, " -u, --userspace Apply to the user-space tracer\n");
105 fprintf(ofp, "\n");
106 fprintf(ofp, "Channel options:\n");
107 fprintf(ofp, " --discard Discard event when buffers are full%s\n",
108 DEFAULT_CHANNEL_OVERWRITE ? "" : " (default)");
109 fprintf(ofp, " --overwrite Flight recorder mode%s\n",
110 DEFAULT_CHANNEL_OVERWRITE ? " (default)" : "");
111 fprintf(ofp, " --subbuf-size SIZE Subbuffer size in bytes {+k,+M,+G}\n");
112 fprintf(ofp, " (default UST uid: %zu, UST pid: %zu, kernel: %zu, metadata: %zu)\n",
113 default_get_ust_uid_channel_subbuf_size(),
114 default_get_ust_pid_channel_subbuf_size(),
115 default_get_kernel_channel_subbuf_size(),
116 default_get_metadata_subbuf_size());
117 fprintf(ofp, " Rounded up to the next power of 2.\n");
118 fprintf(ofp, " --num-subbuf NUM Number of subbufers\n");
119 fprintf(ofp, " (default UST uid: %u, UST pid: %u, kernel: %u, metadata: %u)\n",
120 DEFAULT_UST_UID_CHANNEL_SUBBUF_NUM, DEFAULT_UST_PID_CHANNEL_SUBBUF_NUM,
121 DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM, DEFAULT_METADATA_SUBBUF_NUM);
122 fprintf(ofp, " Rounded up to the next power of 2.\n");
123 fprintf(ofp, " --switch-timer USEC Switch timer interval in usec\n");
124 fprintf(ofp, " (default UST uid: %u, UST pid: %u, kernel: %u, metadata: %u)\n",
125 DEFAULT_UST_UID_CHANNEL_SWITCH_TIMER, DEFAULT_UST_PID_CHANNEL_SWITCH_TIMER,
126 DEFAULT_KERNEL_CHANNEL_SWITCH_TIMER, DEFAULT_METADATA_SWITCH_TIMER);
127 fprintf(ofp, " --read-timer USEC Read timer interval in usec.\n");
128 fprintf(ofp, " (default UST uid: %u, UST pid: %u, kernel: %u, metadata: %u)\n",
129 DEFAULT_UST_UID_CHANNEL_READ_TIMER, DEFAULT_UST_UID_CHANNEL_READ_TIMER,
130 DEFAULT_KERNEL_CHANNEL_READ_TIMER, DEFAULT_METADATA_READ_TIMER);
131 fprintf(ofp, " --output TYPE Channel output type (Values: %s, %s)\n",
132 output_mmap, output_splice);
133 fprintf(ofp, " (default UST uid: %s, UST pid: %s, kernel: %s, metadata: %s)\n",
134 DEFAULT_UST_UID_CHANNEL_OUTPUT == LTTNG_EVENT_MMAP ? output_mmap : output_splice,
135 DEFAULT_UST_PID_CHANNEL_OUTPUT == LTTNG_EVENT_MMAP ? output_mmap : output_splice,
136 DEFAULT_KERNEL_CHANNEL_OUTPUT == LTTNG_EVENT_MMAP ? output_mmap : output_splice,
137 DEFAULT_METADATA_OUTPUT == LTTNG_EVENT_MMAP ? output_mmap : output_splice);
138 fprintf(ofp, " --buffers-uid Use per UID buffer (-u only)\n");
139 fprintf(ofp, " --buffers-pid Use per PID buffer (-u only)\n");
140 fprintf(ofp, " --buffers-global Use shared buffer for the whole system (-k only)\n");
141 fprintf(ofp, " -C, --tracefile-size SIZE\n");
142 fprintf(ofp, " Maximum size of each tracefile within a stream (in bytes). 0 means unlimited.\n");
143 fprintf(ofp, " (default: %u)\n", DEFAULT_CHANNEL_TRACEFILE_SIZE);
144 fprintf(ofp, " Note: traces generated with this option may inaccurately report\n");
145 fprintf(ofp, " discarded events as per CTF 1.8.\n");
146 fprintf(ofp, " -W, --tracefile-count COUNT\n");
147 fprintf(ofp, " Used in conjunction with -C option, this will limit the number\n");
148 fprintf(ofp, " of files created to the specified count. 0 means unlimited.\n");
149 fprintf(ofp, " (default: %u)\n", DEFAULT_CHANNEL_TRACEFILE_COUNT);
150 fprintf(ofp, "\n");
151 }
152
153 /*
154 * Set default attributes depending on those already defined from the command
155 * line.
156 */
157 static void set_default_attr(struct lttng_domain *dom)
158 {
159 struct lttng_channel_attr default_attr;
160
161 /* Set attributes */
162 lttng_channel_set_default_attr(dom, &default_attr);
163
164 if (chan.attr.overwrite == -1) {
165 chan.attr.overwrite = default_attr.overwrite;
166 }
167 if (chan.attr.subbuf_size == -1) {
168 chan.attr.subbuf_size = default_attr.subbuf_size;
169 }
170 if (chan.attr.num_subbuf == -1) {
171 chan.attr.num_subbuf = default_attr.num_subbuf;
172 }
173 if (chan.attr.switch_timer_interval == -1) {
174 chan.attr.switch_timer_interval = default_attr.switch_timer_interval;
175 }
176 if (chan.attr.read_timer_interval == -1) {
177 chan.attr.read_timer_interval = default_attr.read_timer_interval;
178 }
179 if ((int) chan.attr.output == -1) {
180 chan.attr.output = default_attr.output;
181 }
182 if (chan.attr.tracefile_count == -1) {
183 chan.attr.tracefile_count = default_attr.tracefile_count;
184 }
185 if (chan.attr.tracefile_size == -1) {
186 chan.attr.tracefile_size = default_attr.tracefile_size;
187 }
188 }
189
190 /*
191 * Adding channel using the lttng API.
192 */
193 static int enable_channel(char *session_name)
194 {
195 int ret = CMD_SUCCESS, warn = 0, error = 0, success = 0;
196 char *channel_name;
197 struct lttng_domain dom;
198
199 memset(&dom, 0, sizeof(dom));
200
201 /* Create lttng domain */
202 if (opt_kernel) {
203 dom.type = LTTNG_DOMAIN_KERNEL;
204 dom.buf_type = LTTNG_BUFFER_GLOBAL;
205 if (opt_buffer_uid || opt_buffer_pid) {
206 ERR("Buffer type not supported for domain -k");
207 ret = CMD_ERROR;
208 goto error;
209 }
210 } else if (opt_userspace) {
211 dom.type = LTTNG_DOMAIN_UST;
212 if (opt_buffer_pid) {
213 dom.buf_type = LTTNG_BUFFER_PER_PID;
214 } else {
215 if (opt_buffer_global) {
216 ERR("Buffer type not supported for domain -u");
217 ret = CMD_ERROR;
218 goto error;
219 }
220 dom.buf_type = LTTNG_BUFFER_PER_UID;
221 }
222 } else {
223 print_missing_domain();
224 ret = CMD_ERROR;
225 goto error;
226 }
227
228 set_default_attr(&dom);
229
230 if (chan.attr.tracefile_size == 0 && chan.attr.tracefile_count) {
231 ERR("Missing option --tracefile-size. "
232 "A file count without a size won't do anything.");
233 ret = CMD_ERROR;
234 goto error;
235 }
236
237 if ((chan.attr.tracefile_size > 0) &&
238 (chan.attr.tracefile_size < chan.attr.subbuf_size)) {
239 WARN("Tracefile size rounded up from (%" PRIu64 ") to subbuffer size (%" PRIu64 ")",
240 chan.attr.tracefile_size, chan.attr.subbuf_size);
241 chan.attr.tracefile_size = chan.attr.subbuf_size;
242 }
243
244 /* Setting channel output */
245 if (opt_output) {
246 if (!strncmp(output_mmap, opt_output, strlen(output_mmap))) {
247 chan.attr.output = LTTNG_EVENT_MMAP;
248 } else if (!strncmp(output_splice, opt_output, strlen(output_splice))) {
249 chan.attr.output = LTTNG_EVENT_SPLICE;
250 } else {
251 ERR("Unknown output type %s. Possible values are: %s, %s\n",
252 opt_output, output_mmap, output_splice);
253 usage(stderr);
254 ret = CMD_ERROR;
255 goto error;
256 }
257 }
258
259 handle = lttng_create_handle(session_name, &dom);
260 if (handle == NULL) {
261 ret = -1;
262 goto error;
263 }
264
265 /* Mi open channels element */
266 if (lttng_opt_mi) {
267 assert(writer);
268 ret = mi_lttng_channels_open(writer);
269 if (ret) {
270 ret = CMD_ERROR;
271 goto error;
272 }
273 }
274
275 /* Strip channel list (format: chan1,chan2,...) */
276 channel_name = strtok(opt_channels, ",");
277 while (channel_name != NULL) {
278 /* Copy channel name and normalize it */
279 strncpy(chan.name, channel_name, NAME_MAX);
280 chan.name[NAME_MAX - 1] = '\0';
281
282 DBG("Enabling channel %s", channel_name);
283
284 ret = lttng_enable_channel(handle, &chan);
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 default:
296 ERR("Channel %s: %s (session %s)", channel_name,
297 lttng_strerror(ret), session_name);
298 error = 1;
299 break;
300 }
301 } else {
302 MSG("%s channel %s enabled for session %s",
303 get_domain_str(dom.type), channel_name, session_name);
304 success = 1;
305 }
306
307 if (lttng_opt_mi) {
308 /* Mi print the channel element and leave it open */
309 ret = mi_lttng_channel(writer, &chan, 1);
310 if (ret) {
311 ret = CMD_ERROR;
312 goto error;
313 }
314
315 /* Individual Success ? */
316 ret = mi_lttng_writer_write_element_bool(writer,
317 mi_lttng_element_command_success, success);
318 if (ret) {
319 ret = CMD_ERROR;
320 goto error;
321 }
322
323 /* Close channel element */
324 ret = mi_lttng_writer_close_element(writer);
325 if (ret) {
326 ret = CMD_ERROR;
327 goto error;
328 }
329 }
330
331 /* Next channel */
332 channel_name = strtok(NULL, ",");
333 }
334
335 if (lttng_opt_mi) {
336 /* Close channels element */
337 ret = mi_lttng_writer_close_element(writer);
338 if (ret) {
339 ret = CMD_ERROR;
340 goto error;
341 }
342 }
343
344 ret = CMD_SUCCESS;
345
346 error:
347 /* If more important error happen bypass the warning */
348 if (!ret && warn) {
349 ret = CMD_WARNING;
350 }
351 /* If more important error happen bypass the warning */
352 if (!ret && error) {
353 ret = CMD_ERROR;
354 }
355
356 lttng_destroy_handle(handle);
357
358 return ret;
359 }
360
361 /*
362 * Default value for channel configuration.
363 */
364 static void init_channel_config(void)
365 {
366 /*
367 * Put -1 everywhere so we can identify those set by the command line and
368 * those needed to be set by the default values.
369 */
370 memset(&chan.attr, -1, sizeof(chan.attr));
371 }
372
373 /*
374 * Add channel to trace session
375 */
376 int cmd_enable_channels(int argc, const char **argv)
377 {
378 int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1;
379 static poptContext pc;
380 char *session_name = NULL;
381 char *opt_arg = NULL;
382
383 init_channel_config();
384
385 pc = poptGetContext(NULL, argc, argv, long_options, 0);
386 poptReadDefaultConfig(pc, 0);
387
388 while ((opt = poptGetNextOpt(pc)) != -1) {
389 switch (opt) {
390 case OPT_HELP:
391 usage(stdout);
392 goto end;
393 case OPT_DISCARD:
394 chan.attr.overwrite = 0;
395 DBG("Channel set to discard");
396 break;
397 case OPT_OVERWRITE:
398 chan.attr.overwrite = 1;
399 DBG("Channel set to overwrite");
400 break;
401 case OPT_SUBBUF_SIZE:
402 {
403 uint64_t rounded_size;
404 int order;
405
406 /* Parse the size */
407 opt_arg = poptGetOptArg(pc);
408 if (utils_parse_size_suffix(opt_arg, &chan.attr.subbuf_size) < 0 || !chan.attr.subbuf_size) {
409 ERR("Wrong value in --subbuf-size parameter: %s", opt_arg);
410 ret = CMD_ERROR;
411 goto end;
412 }
413
414 order = get_count_order_u64(chan.attr.subbuf_size);
415 assert(order >= 0);
416 rounded_size = 1ULL << order;
417 if (rounded_size < chan.attr.subbuf_size) {
418 ERR("The subbuf size (%" PRIu64 ") is rounded and overflows!",
419 chan.attr.subbuf_size);
420 ret = CMD_ERROR;
421 goto end;
422 }
423
424 if (rounded_size != chan.attr.subbuf_size) {
425 WARN("The subbuf size (%" PRIu64 ") is rounded to the next power of 2 (%" PRIu64 ")",
426 chan.attr.subbuf_size, rounded_size);
427 chan.attr.subbuf_size = rounded_size;
428 }
429
430 /* Should now be power of 2 */
431 assert(!((chan.attr.subbuf_size - 1) & chan.attr.subbuf_size));
432
433 DBG("Channel subbuf size set to %" PRIu64, chan.attr.subbuf_size);
434 break;
435 }
436 case OPT_NUM_SUBBUF:
437 {
438 uint64_t rounded_size;
439 int order;
440
441 errno = 0;
442 opt_arg = poptGetOptArg(pc);
443 chan.attr.num_subbuf = strtoull(opt_arg, NULL, 0);
444 if (errno != 0 || !chan.attr.num_subbuf || !isdigit(opt_arg[0])) {
445 ERR("Wrong value in --num-subbuf parameter: %s", opt_arg);
446 ret = CMD_ERROR;
447 goto end;
448 }
449
450 order = get_count_order_u64(chan.attr.num_subbuf);
451 assert(order >= 0);
452 rounded_size = 1ULL << order;
453 if (rounded_size < chan.attr.num_subbuf) {
454 ERR("The number of subbuffers (%" PRIu64 ") is rounded and overflows!",
455 chan.attr.num_subbuf);
456 ret = CMD_ERROR;
457 goto end;
458 }
459
460 if (rounded_size != chan.attr.num_subbuf) {
461 WARN("The number of subbuffers (%" PRIu64 ") is rounded to the next power of 2 (%" PRIu64 ")",
462 chan.attr.num_subbuf, rounded_size);
463 chan.attr.num_subbuf = rounded_size;
464 }
465
466 /* Should now be power of 2 */
467 assert(!((chan.attr.num_subbuf - 1) & chan.attr.num_subbuf));
468
469 DBG("Channel subbuf num set to %" PRIu64, chan.attr.num_subbuf);
470 break;
471 }
472 case OPT_SWITCH_TIMER:
473 {
474 unsigned long v;
475
476 errno = 0;
477 opt_arg = poptGetOptArg(pc);
478 v = strtoul(opt_arg, NULL, 0);
479 if (errno != 0 || !isdigit(opt_arg[0])) {
480 ERR("Wrong value in --switch-timer parameter: %s", opt_arg);
481 ret = CMD_ERROR;
482 goto end;
483 }
484 if (v != (uint32_t) v) {
485 ERR("32-bit overflow in --switch-timer parameter: %s", opt_arg);
486 ret = CMD_ERROR;
487 goto end;
488 }
489 chan.attr.switch_timer_interval = (uint32_t) v;
490 DBG("Channel switch timer interval set to %d", chan.attr.switch_timer_interval);
491 break;
492 }
493 case OPT_READ_TIMER:
494 {
495 unsigned long v;
496
497 errno = 0;
498 opt_arg = poptGetOptArg(pc);
499 v = strtoul(opt_arg, NULL, 0);
500 if (errno != 0 || !isdigit(opt_arg[0])) {
501 ERR("Wrong value in --read-timer parameter: %s", opt_arg);
502 ret = CMD_ERROR;
503 goto end;
504 }
505 if (v != (uint32_t) v) {
506 ERR("32-bit overflow in --read-timer parameter: %s", opt_arg);
507 ret = CMD_ERROR;
508 goto end;
509 }
510 chan.attr.read_timer_interval = (uint32_t) v;
511 DBG("Channel read timer interval set to %d", chan.attr.read_timer_interval);
512 break;
513 }
514 case OPT_USERSPACE:
515 opt_userspace = 1;
516 break;
517 case OPT_TRACEFILE_SIZE:
518 opt_arg = poptGetOptArg(pc);
519 if (utils_parse_size_suffix(opt_arg, &chan.attr.tracefile_size) < 0) {
520 ERR("Wrong value in --tracefile-size parameter: %s", opt_arg);
521 ret = CMD_ERROR;
522 goto end;
523 }
524 DBG("Maximum tracefile size set to %" PRIu64,
525 chan.attr.tracefile_size);
526 break;
527 case OPT_TRACEFILE_COUNT:
528 {
529 unsigned long v;
530
531 errno = 0;
532 opt_arg = poptGetOptArg(pc);
533 v = strtoul(opt_arg, NULL, 0);
534 if (errno != 0 || !isdigit(opt_arg[0])) {
535 ERR("Wrong value in --tracefile-count parameter: %s", opt_arg);
536 ret = CMD_ERROR;
537 goto end;
538 }
539 if (v != (uint32_t) v) {
540 ERR("32-bit overflow in --tracefile-count parameter: %s", opt_arg);
541 ret = CMD_ERROR;
542 goto end;
543 }
544 chan.attr.tracefile_count = (uint32_t) v;
545 DBG("Maximum tracefile count set to %" PRIu64,
546 chan.attr.tracefile_count);
547 break;
548 }
549 case OPT_LIST_OPTIONS:
550 list_cmd_options(stdout, long_options);
551 goto end;
552 default:
553 usage(stderr);
554 ret = CMD_UNDEFINED;
555 goto end;
556 }
557 }
558
559 /* Mi check */
560 if (lttng_opt_mi) {
561 writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi);
562 if (!writer) {
563 ret = -LTTNG_ERR_NOMEM;
564 goto end;
565 }
566
567 /* Open command element */
568 ret = mi_lttng_writer_command_open(writer,
569 mi_lttng_element_command_enable_channels);
570 if (ret) {
571 ret = CMD_ERROR;
572 goto end;
573 }
574
575 /* Open output element */
576 ret = mi_lttng_writer_open_element(writer,
577 mi_lttng_element_command_output);
578 if (ret) {
579 ret = CMD_ERROR;
580 goto end;
581 }
582 }
583
584 opt_channels = (char*) poptGetArg(pc);
585 if (opt_channels == NULL) {
586 ERR("Missing channel name.\n");
587 usage(stderr);
588 ret = CMD_ERROR;
589 success = 0;
590 goto mi_closing;
591 }
592
593 if (!opt_session_name) {
594 session_name = get_session_name();
595 if (session_name == NULL) {
596 command_ret = CMD_ERROR;
597 success = 0;
598 goto mi_closing;
599 }
600 } else {
601 session_name = opt_session_name;
602 }
603
604 command_ret = enable_channel(session_name);
605 if (command_ret) {
606 success = 0;
607 }
608
609 mi_closing:
610 /* Mi closing */
611 if (lttng_opt_mi) {
612 /* Close output element */
613 ret = mi_lttng_writer_close_element(writer);
614 if (ret) {
615 goto end;
616 }
617
618 /* Success ? */
619 ret = mi_lttng_writer_write_element_bool(writer,
620 mi_lttng_element_command_success, success);
621 if (ret) {
622 goto end;
623 }
624
625 /* Command element close */
626 ret = mi_lttng_writer_command_close(writer);
627 if (ret) {
628 goto end;
629 }
630 }
631
632 end:
633 /* Mi clean-up */
634 if (writer && mi_lttng_writer_destroy(writer)) {
635 /* Preserve original error code */
636 ret = ret ? ret : LTTNG_ERR_MI_IO_FAIL;
637 }
638
639 if (!opt_session_name && session_name) {
640 free(session_name);
641 }
642
643 /* Overwrite ret if an error occurred when enable_channel */
644 ret = command_ret ? command_ret : ret;
645 poptFreeContext(pc);
646 return ret;
647 }
This page took 0.042647 seconds and 4 git commands to generate.