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