Fix: return EINVAL if agent registration fails
[lttng-tools.git] / src / bin / lttng / commands / list.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 #include <inttypes.h>
20 #include <popt.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <assert.h>
25
26 #include <common/mi-lttng.h>
27
28 #include "../command.h"
29
30 static int opt_userspace;
31 static int opt_kernel;
32 static int opt_jul;
33 static int opt_log4j;
34 static char *opt_channel;
35 static int opt_domain;
36 static int opt_fields;
37 static int opt_syscall;
38 #if 0
39 /* Not implemented yet */
40 static char *opt_cmd_name;
41 static pid_t opt_pid;
42 #endif
43
44 const char *indent4 = " ";
45 const char *indent6 = " ";
46 const char *indent8 = " ";
47
48 enum {
49 OPT_HELP = 1,
50 OPT_USERSPACE,
51 OPT_LIST_OPTIONS,
52 };
53
54 static struct lttng_handle *handle;
55 static struct mi_writer *writer;
56
57 static struct poptOption long_options[] = {
58 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
59 {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
60 {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
61 {"jul", 'j', POPT_ARG_VAL, &opt_jul, 1, 0, 0},
62 {"log4j", 'l', POPT_ARG_VAL, &opt_log4j, 1, 0, 0},
63 #if 0
64 /* Not implemented yet */
65 {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_cmd_name, OPT_USERSPACE, 0, 0},
66 {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0},
67 #else
68 {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0},
69 #endif
70 {"channel", 'c', POPT_ARG_STRING, &opt_channel, 0, 0, 0},
71 {"domain", 'd', POPT_ARG_VAL, &opt_domain, 1, 0, 0},
72 {"fields", 'f', POPT_ARG_VAL, &opt_fields, 1, 0, 0},
73 {"syscall", 'S', POPT_ARG_VAL, &opt_syscall, 1, 0, 0},
74 {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
75 {0, 0, 0, 0, 0, 0, 0}
76 };
77
78 /*
79 * usage
80 */
81 static void usage(FILE *ofp)
82 {
83 fprintf(ofp, "usage: lttng list [OPTIONS] [SESSION [SESSION OPTIONS]]\n");
84 fprintf(ofp, "\n");
85 fprintf(ofp, "With no arguments, list available tracing session(s)\n");
86 fprintf(ofp, "\n");
87 fprintf(ofp, "Without a session, -k lists available kernel events\n");
88 fprintf(ofp, "Without a session, -u lists available userspace events\n");
89 fprintf(ofp, "\n");
90 fprintf(ofp, " -h, --help Show this help\n");
91 fprintf(ofp, " --list-options Simple listing of options\n");
92 fprintf(ofp, " -k, --kernel Select kernel domain\n");
93 fprintf(ofp, " -u, --userspace Select user-space domain.\n");
94 fprintf(ofp, " -j, --jul Apply for Java application using JUL\n");
95 fprintf(ofp, " -l, --log4j Apply for Java application using LOG4J\n");
96 fprintf(ofp, " -f, --fields List event fields.\n");
97 fprintf(ofp, " --syscall List available system calls.\n");
98 #if 0
99 fprintf(ofp, " -p, --pid PID List user-space events by PID\n");
100 #endif
101 fprintf(ofp, "\n");
102 fprintf(ofp, "Session Options:\n");
103 fprintf(ofp, " -c, --channel NAME List details of a channel\n");
104 fprintf(ofp, " -d, --domain List available domain(s)\n");
105 fprintf(ofp, "\n");
106 }
107
108 /*
109 * Get command line from /proc for a specific pid.
110 *
111 * On success, return an allocated string pointer to the proc cmdline.
112 * On error, return NULL.
113 */
114 static char *get_cmdline_by_pid(pid_t pid)
115 {
116 int ret;
117 FILE *fp = NULL;
118 char *cmdline = NULL;
119 char path[20]; /* Can't go bigger than /proc/65535/cmdline */
120
121 snprintf(path, sizeof(path), "/proc/%d/cmdline", pid);
122 fp = fopen(path, "r");
123 if (fp == NULL) {
124 goto end;
125 }
126
127 /* Caller must free() *cmdline */
128 cmdline = malloc(PATH_MAX);
129 if (!cmdline) {
130 perror("malloc cmdline");
131 goto end;
132 }
133 ret = fread(cmdline, 1, PATH_MAX, fp);
134 if (ret < 0) {
135 perror("fread proc list");
136 }
137
138 end:
139 if (fp) {
140 fclose(fp);
141 }
142 return cmdline;
143 }
144
145 static
146 const char *active_string(int value)
147 {
148 switch (value) {
149 case 0: return "inactive";
150 case 1: return "active";
151 case -1: return "";
152 default: return NULL;
153 }
154 }
155
156 static const char *snapshot_string(int value)
157 {
158 switch (value) {
159 case 1:
160 return " snapshot";
161 default:
162 return "";
163 }
164 }
165
166 static
167 const char *enabled_string(int value)
168 {
169 switch (value) {
170 case 0: return " [disabled]";
171 case 1: return " [enabled]";
172 case -1: return "";
173 default: return NULL;
174 }
175 }
176
177 static
178 const char *filter_string(int value)
179 {
180 switch (value) {
181 case 1: return " [with filter]";
182 default: return "";
183 }
184 }
185
186 static
187 const char *exclusion_string(int value)
188 {
189 switch (value) {
190 case 1: return " [has exclusions]";
191 default: return "";
192 }
193 }
194
195 static const char *logleveltype_string(enum lttng_loglevel_type value)
196 {
197 switch (value) {
198 case LTTNG_EVENT_LOGLEVEL_ALL:
199 return ":";
200 case LTTNG_EVENT_LOGLEVEL_RANGE:
201 return " <=";
202 case LTTNG_EVENT_LOGLEVEL_SINGLE:
203 return " ==";
204 default:
205 return " <<TYPE UNKN>>";
206 }
207 }
208
209 static const char *bitness_event(enum lttng_event_flag flags)
210 {
211 if (flags & LTTNG_EVENT_FLAG_SYSCALL_32) {
212 if (flags & LTTNG_EVENT_FLAG_SYSCALL_64) {
213 return " [32/64-bit]";
214 } else {
215 return " [32-bit]";
216 }
217 } else if (flags & LTTNG_EVENT_FLAG_SYSCALL_64) {
218 return " [64-bit]";
219 } else {
220 return "";
221 }
222 }
223
224 /*
225 * Pretty print single event.
226 */
227 static void print_events(struct lttng_event *event)
228 {
229 switch (event->type) {
230 case LTTNG_EVENT_TRACEPOINT:
231 {
232 if (event->loglevel != -1) {
233 MSG("%s%s (loglevel%s %s (%d)) (type: tracepoint)%s%s%s",
234 indent6,
235 event->name,
236 logleveltype_string(event->loglevel_type),
237 mi_lttng_loglevel_string(event->loglevel, handle->domain.type),
238 event->loglevel,
239 enabled_string(event->enabled),
240 exclusion_string(event->exclusion),
241 filter_string(event->filter));
242 } else {
243 MSG("%s%s (type: tracepoint)%s%s%s",
244 indent6,
245 event->name,
246 enabled_string(event->enabled),
247 exclusion_string(event->exclusion),
248 filter_string(event->filter));
249 }
250 break;
251 }
252 case LTTNG_EVENT_FUNCTION:
253 MSG("%s%s (type: function)%s%s", indent6,
254 event->name, enabled_string(event->enabled),
255 filter_string(event->filter));
256 if (event->attr.probe.addr != 0) {
257 MSG("%saddr: 0x%" PRIx64, indent8, event->attr.probe.addr);
258 } else {
259 MSG("%soffset: 0x%" PRIx64, indent8, event->attr.probe.offset);
260 MSG("%ssymbol: %s", indent8, event->attr.probe.symbol_name);
261 }
262 break;
263 case LTTNG_EVENT_PROBE:
264 MSG("%s%s (type: probe)%s%s", indent6,
265 event->name, enabled_string(event->enabled),
266 filter_string(event->filter));
267 if (event->attr.probe.addr != 0) {
268 MSG("%saddr: 0x%" PRIx64, indent8, event->attr.probe.addr);
269 } else {
270 MSG("%soffset: 0x%" PRIx64, indent8, event->attr.probe.offset);
271 MSG("%ssymbol: %s", indent8, event->attr.probe.symbol_name);
272 }
273 break;
274 case LTTNG_EVENT_FUNCTION_ENTRY:
275 MSG("%s%s (type: function)%s%s", indent6,
276 event->name, enabled_string(event->enabled),
277 filter_string(event->filter));
278 MSG("%ssymbol: \"%s\"", indent8, event->attr.ftrace.symbol_name);
279 break;
280 case LTTNG_EVENT_SYSCALL:
281 MSG("%s%s%s%s%s", indent6, event->name,
282 (opt_syscall ? "" : " (type:syscall)"),
283 enabled_string(event->enabled),
284 bitness_event(event->flags));
285 break;
286 case LTTNG_EVENT_NOOP:
287 MSG("%s (type: noop)%s%s", indent6,
288 enabled_string(event->enabled),
289 filter_string(event->filter));
290 break;
291 case LTTNG_EVENT_ALL:
292 /* We should never have "all" events in list. */
293 assert(0);
294 break;
295 }
296 }
297
298 static const char *field_type(struct lttng_event_field *field)
299 {
300 switch(field->type) {
301 case LTTNG_EVENT_FIELD_INTEGER:
302 return "integer";
303 case LTTNG_EVENT_FIELD_ENUM:
304 return "enum";
305 case LTTNG_EVENT_FIELD_FLOAT:
306 return "float";
307 case LTTNG_EVENT_FIELD_STRING:
308 return "string";
309 case LTTNG_EVENT_FIELD_OTHER:
310 default: /* fall-through */
311 return "unknown";
312 }
313 }
314
315 /*
316 * Pretty print single event fields.
317 */
318 static void print_event_field(struct lttng_event_field *field)
319 {
320 if (!field->field_name[0]) {
321 return;
322 }
323 MSG("%sfield: %s (%s)%s", indent8, field->field_name,
324 field_type(field), field->nowrite ? " [no write]" : "");
325 }
326
327 /*
328 * Machine interface
329 * Jul and ust event listing
330 */
331 static int mi_list_agent_ust_events(struct lttng_event *events, int count,
332 struct lttng_domain *domain)
333 {
334 int ret, i;
335 pid_t cur_pid = 0;
336 char *cmdline = NULL;
337 int pid_element_open = 0;
338
339 /* Open domains element */
340 ret = mi_lttng_domains_open(writer);
341 if (ret) {
342 goto end;
343 }
344
345 /* Write domain */
346 ret = mi_lttng_domain(writer, domain, 1);
347 if (ret) {
348 goto end;
349 }
350
351 /* Open pids element */
352 ret = mi_lttng_pids_open(writer);
353 if (ret) {
354 goto end;
355 }
356
357 for (i = 0; i < count; i++) {
358 if (cur_pid != events[i].pid) {
359 if (pid_element_open) {
360 /* Close the previous events and pid element */
361 ret = mi_lttng_close_multi_element(writer, 2);
362 if (ret) {
363 goto end;
364 }
365 pid_element_open = 0;
366 }
367
368 cur_pid = events[i].pid;
369 cmdline = get_cmdline_by_pid(cur_pid);
370 if (!cmdline) {
371 ret = CMD_ERROR;
372 goto end;
373 }
374
375 if (!pid_element_open) {
376 /* Open and write a pid element */
377 ret = mi_lttng_pid(writer, cur_pid, cmdline, 1);
378 if (ret) {
379 goto error;
380 }
381
382 /* Open events element */
383 ret = mi_lttng_events_open(writer);
384 if (ret) {
385 goto error;
386 }
387
388 pid_element_open = 1;
389 }
390 free(cmdline);
391 }
392
393 /* Write an event */
394 ret = mi_lttng_event(writer, &events[i], 0, handle->domain.type);
395 if (ret) {
396 goto end;
397 }
398 }
399
400 /* Close pids */
401 ret = mi_lttng_writer_close_element(writer);
402 if (ret) {
403 goto end;
404 }
405
406 /* Close domain, domains */
407 ret = mi_lttng_close_multi_element(writer, 2);
408 end:
409 return ret;
410 error:
411 free(cmdline);
412 return ret;
413 }
414
415 static int list_agent_events(void)
416 {
417 int i, size, ret = CMD_SUCCESS;
418 struct lttng_domain domain;
419 struct lttng_handle *handle;
420 struct lttng_event *event_list;
421 pid_t cur_pid = 0;
422 char *cmdline = NULL;
423 const char *agent_domain_str;
424
425 memset(&domain, 0, sizeof(domain));
426 if (opt_jul) {
427 domain.type = LTTNG_DOMAIN_JUL;
428 } else if (opt_log4j) {
429 domain.type = LTTNG_DOMAIN_LOG4J;
430 }
431
432 agent_domain_str = get_domain_str(domain.type);
433
434 DBG("Getting %s tracing events", agent_domain_str);
435
436 handle = lttng_create_handle(NULL, &domain);
437 if (handle == NULL) {
438 ret = CMD_ERROR;
439 goto end;
440 }
441
442 size = lttng_list_tracepoints(handle, &event_list);
443 if (size < 0) {
444 ERR("Unable to list %s events: %s", agent_domain_str,
445 lttng_strerror(size));
446 ret = CMD_ERROR;
447 goto end;
448 }
449
450 if (lttng_opt_mi) {
451 /* Mi print */
452 ret = mi_list_agent_ust_events(event_list, size, &domain);
453 if (ret) {
454 ret = CMD_ERROR;
455 goto error;
456 }
457 } else {
458 /* Pretty print */
459 MSG("%s events (Logger name):\n-------------------------",
460 agent_domain_str);
461
462 if (size == 0) {
463 MSG("None");
464 }
465
466 for (i = 0; i < size; i++) {
467 if (cur_pid != event_list[i].pid) {
468 cur_pid = event_list[i].pid;
469 cmdline = get_cmdline_by_pid(cur_pid);
470 if (cmdline == NULL) {
471 ret = CMD_ERROR;
472 goto error;
473 }
474 MSG("\nPID: %d - Name: %s", cur_pid, cmdline);
475 free(cmdline);
476 }
477 MSG("%s- %s", indent6, event_list[i].name);
478 }
479
480 MSG("");
481 }
482
483 error:
484 free(event_list);
485 end:
486 lttng_destroy_handle(handle);
487 return ret;
488 }
489
490 /*
491 * Ask session daemon for all user space tracepoints available.
492 */
493 static int list_ust_events(void)
494 {
495 int i, size, ret = CMD_SUCCESS;
496 struct lttng_domain domain;
497 struct lttng_handle *handle;
498 struct lttng_event *event_list;
499 pid_t cur_pid = 0;
500 char *cmdline = NULL;
501
502 memset(&domain, 0, sizeof(domain));
503
504 DBG("Getting UST tracing events");
505
506 domain.type = LTTNG_DOMAIN_UST;
507
508 handle = lttng_create_handle(NULL, &domain);
509 if (handle == NULL) {
510 ret = CMD_ERROR;
511 goto end;
512 }
513
514 size = lttng_list_tracepoints(handle, &event_list);
515 if (size < 0) {
516 ERR("Unable to list UST events: %s", lttng_strerror(size));
517 ret = CMD_ERROR;
518 goto error;
519 }
520
521 if (lttng_opt_mi) {
522 /* Mi print */
523 ret = mi_list_agent_ust_events(event_list, size, &domain);
524 } else {
525 /* Pretty print */
526 MSG("UST events:\n-------------");
527
528 if (size == 0) {
529 MSG("None");
530 }
531
532 for (i = 0; i < size; i++) {
533 if (cur_pid != event_list[i].pid) {
534 cur_pid = event_list[i].pid;
535 cmdline = get_cmdline_by_pid(cur_pid);
536 if (cmdline == NULL) {
537 ret = CMD_ERROR;
538 goto error;
539 }
540 MSG("\nPID: %d - Name: %s", cur_pid, cmdline);
541 free(cmdline);
542 }
543 print_events(&event_list[i]);
544 }
545
546 MSG("");
547 }
548
549 error:
550 free(event_list);
551 end:
552 lttng_destroy_handle(handle);
553 return ret;
554 }
555
556 /*
557 * Machine interface
558 * List all ust event with their fields
559 */
560 static int mi_list_ust_event_fields(struct lttng_event_field *fields, int count,
561 struct lttng_domain *domain)
562 {
563 int ret, i;
564 pid_t cur_pid = 0;
565 char *cmdline = NULL;
566 int pid_element_open = 0;
567 int event_element_open = 0;
568 struct lttng_event cur_event;
569
570 /* Open domains element */
571 ret = mi_lttng_domains_open(writer);
572 if (ret) {
573 goto end;
574 }
575
576 /* Write domain */
577 ret = mi_lttng_domain(writer, domain, 1);
578 if (ret) {
579 goto end;
580 }
581
582 /* Open pids element */
583 ret = mi_lttng_pids_open(writer);
584 if (ret) {
585 goto end;
586 }
587
588 for (i = 0; i < count; i++) {
589 if (cur_pid != fields[i].event.pid) {
590 if (pid_element_open) {
591 if (event_element_open) {
592
593 /* Close the previous field element and event. */
594 ret = mi_lttng_close_multi_element(writer, 2);
595 if (ret) {
596 goto end;
597 }
598 event_element_open = 0;
599 }
600 /* Close the previous events, pid element */
601 ret = mi_lttng_close_multi_element(writer, 2);
602 if (ret) {
603 goto end;
604 }
605 pid_element_open = 0;
606 }
607
608 cur_pid = fields[i].event.pid;
609 cmdline = get_cmdline_by_pid(cur_pid);
610 if (!pid_element_open) {
611 /* Open and write a pid element */
612 ret = mi_lttng_pid(writer, cur_pid, cmdline, 1);
613 if (ret) {
614 goto error;
615 }
616
617 /* Open events element */
618 ret = mi_lttng_events_open(writer);
619 if (ret) {
620 goto error;
621 }
622 pid_element_open = 1;
623 }
624 free(cmdline);
625 /* Wipe current event since we are about to print a new PID. */
626 memset(&cur_event, 0, sizeof(cur_event));
627 }
628
629 if (strcmp(cur_event.name, fields[i].event.name) != 0) {
630 if (event_element_open) {
631 /* Close the previous fields element and the previous event */
632 ret = mi_lttng_close_multi_element(writer, 2);
633 if (ret) {
634 goto end;
635 }
636 event_element_open = 0;
637 }
638
639 memcpy(&cur_event, &fields[i].event,
640 sizeof(cur_event));
641
642 if (!event_element_open) {
643 /* Open and write the event */
644 ret = mi_lttng_event(writer, &cur_event, 1,
645 handle->domain.type);
646 if (ret) {
647 goto end;
648 }
649
650 /* Open a fields element */
651 ret = mi_lttng_event_fields_open(writer);
652 if (ret) {
653 goto end;
654 }
655 event_element_open = 1;
656 }
657 }
658
659 /* Print the event_field */
660 ret = mi_lttng_event_field(writer, &fields[i]);
661 if (ret) {
662 goto end;
663 }
664 }
665
666 /* Close pids, domain, domains */
667 ret = mi_lttng_close_multi_element(writer, 3);
668 end:
669 return ret;
670 error:
671 free(cmdline);
672 return ret;
673 }
674
675 /*
676 * Ask session daemon for all user space tracepoint fields available.
677 */
678 static int list_ust_event_fields(void)
679 {
680 int i, size, ret = CMD_SUCCESS;
681 struct lttng_domain domain;
682 struct lttng_handle *handle;
683 struct lttng_event_field *event_field_list;
684 pid_t cur_pid = 0;
685 char *cmdline = NULL;
686
687 struct lttng_event cur_event;
688
689 memset(&domain, 0, sizeof(domain));
690 memset(&cur_event, 0, sizeof(cur_event));
691
692 DBG("Getting UST tracing event fields");
693
694 domain.type = LTTNG_DOMAIN_UST;
695
696 handle = lttng_create_handle(NULL, &domain);
697 if (handle == NULL) {
698 ret = CMD_ERROR;
699 goto end;
700 }
701
702 size = lttng_list_tracepoint_fields(handle, &event_field_list);
703 if (size < 0) {
704 ERR("Unable to list UST event fields: %s", lttng_strerror(size));
705 ret = CMD_ERROR;
706 goto end;
707 }
708
709 if (lttng_opt_mi) {
710 /* Mi print */
711 ret = mi_list_ust_event_fields(event_field_list, size, &domain);
712 if (ret) {
713 ret = CMD_ERROR;
714 goto error;
715 }
716 } else {
717 /* Pretty print */
718 MSG("UST events:\n-------------");
719
720 if (size == 0) {
721 MSG("None");
722 }
723
724 for (i = 0; i < size; i++) {
725 if (cur_pid != event_field_list[i].event.pid) {
726 cur_pid = event_field_list[i].event.pid;
727 cmdline = get_cmdline_by_pid(cur_pid);
728 if (cmdline == NULL) {
729 ret = CMD_ERROR;
730 goto error;
731 }
732 MSG("\nPID: %d - Name: %s", cur_pid, cmdline);
733 free(cmdline);
734 /* Wipe current event since we are about to print a new PID. */
735 memset(&cur_event, 0, sizeof(cur_event));
736 }
737 if (strcmp(cur_event.name, event_field_list[i].event.name) != 0) {
738 print_events(&event_field_list[i].event);
739 memcpy(&cur_event, &event_field_list[i].event,
740 sizeof(cur_event));
741 }
742 print_event_field(&event_field_list[i]);
743 }
744
745 MSG("");
746 }
747
748 error:
749 free(event_field_list);
750 end:
751 lttng_destroy_handle(handle);
752 return ret;
753 }
754
755 /*
756 * Machine interface
757 * Print a list of kernel events
758 */
759 static int mi_list_kernel_events(struct lttng_event *events, int count,
760 struct lttng_domain *domain)
761 {
762 int ret, i;
763
764 /* Open domains element */
765 ret = mi_lttng_domains_open(writer);
766 if (ret) {
767 goto end;
768 }
769
770 /* Write domain */
771 ret = mi_lttng_domain(writer, domain, 1);
772 if (ret) {
773 goto end;
774 }
775
776 /* Open events */
777 ret = mi_lttng_events_open(writer);
778 if (ret) {
779 goto end;
780 }
781
782 for (i = 0; i < count; i++) {
783 ret = mi_lttng_event(writer, &events[i], 0, handle->domain.type);
784 if (ret) {
785 goto end;
786 }
787 }
788
789 /* close events, domain and domains */
790 ret = mi_lttng_close_multi_element(writer, 3);
791 if (ret) {
792 goto end;
793 }
794
795 end:
796 return ret;
797 }
798
799 /*
800 * Ask for all trace events in the kernel
801 */
802 static int list_kernel_events(void)
803 {
804 int i, size, ret = CMD_SUCCESS;
805 struct lttng_domain domain;
806 struct lttng_handle *handle;
807 struct lttng_event *event_list;
808
809 memset(&domain, 0, sizeof(domain));
810
811 DBG("Getting kernel tracing events");
812
813 domain.type = LTTNG_DOMAIN_KERNEL;
814
815 handle = lttng_create_handle(NULL, &domain);
816 if (handle == NULL) {
817 ret = CMD_ERROR;
818 goto error;
819 }
820
821 size = lttng_list_tracepoints(handle, &event_list);
822 if (size < 0) {
823 ERR("Unable to list kernel events: %s", lttng_strerror(size));
824 lttng_destroy_handle(handle);
825 return CMD_ERROR;
826 }
827
828 if (lttng_opt_mi) {
829 /* Mi print */
830 ret = mi_list_kernel_events(event_list, size, &domain);
831 if (ret) {
832 ret = CMD_ERROR;
833 goto end;
834 }
835 } else {
836 MSG("Kernel events:\n-------------");
837
838 for (i = 0; i < size; i++) {
839 print_events(&event_list[i]);
840 }
841
842 MSG("");
843 }
844
845 end:
846 free(event_list);
847
848 lttng_destroy_handle(handle);
849 return ret;
850
851 error:
852 lttng_destroy_handle(handle);
853 return ret;
854 }
855
856 /*
857 * Machine interface
858 * Print a list of system calls.
859 */
860 static int mi_list_syscalls(struct lttng_event *events, int count)
861 {
862 int ret, i;
863
864 /* Open events */
865 ret = mi_lttng_events_open(writer);
866 if (ret) {
867 goto end;
868 }
869
870 for (i = 0; i < count; i++) {
871 ret = mi_lttng_event(writer, &events[i], 0, handle->domain.type);
872 if (ret) {
873 goto end;
874 }
875 }
876
877 /* Close events. */
878 ret = mi_lttng_writer_close_element(writer);
879 if (ret) {
880 goto end;
881 }
882
883 end:
884 return ret;
885 }
886
887 /*
888 * Ask for kernel system calls.
889 */
890 static int list_syscalls(void)
891 {
892 int i, size, ret = CMD_SUCCESS;
893 struct lttng_event *event_list;
894
895 DBG("Getting kernel system call events");
896
897 size = lttng_list_syscalls(&event_list);
898 if (size < 0) {
899 ERR("Unable to list system calls: %s", lttng_strerror(size));
900 ret = CMD_ERROR;
901 goto error;
902 }
903
904 if (lttng_opt_mi) {
905 /* Mi print */
906 ret = mi_list_syscalls(event_list, size);
907 if (ret) {
908 ret = CMD_ERROR;
909 goto end;
910 }
911 } else {
912 MSG("System calls:\n-------------");
913
914 for (i = 0; i < size; i++) {
915 print_events(&event_list[i]);
916 }
917
918 MSG("");
919 }
920
921 end:
922 free(event_list);
923 return ret;
924
925 error:
926 return ret;
927 }
928
929 /*
930 * Machine Interface
931 * Print a list of agent events
932 */
933 static int mi_list_session_agent_events(struct lttng_event *events, int count)
934 {
935 int ret, i;
936
937 /* Open events element */
938 ret = mi_lttng_events_open(writer);
939 if (ret) {
940 goto end;
941 }
942
943 for (i = 0; i < count; i++) {
944 ret = mi_lttng_event(writer, &events[i], 0, handle->domain.type);
945 if (ret) {
946 goto end;
947 }
948 }
949
950 /* Close events element */
951 ret = mi_lttng_writer_close_element(writer);
952
953 end:
954 return ret;
955 }
956
957 /*
958 * List agent events for a specific session using the handle.
959 *
960 * Return CMD_SUCCESS on success else a negative value.
961 */
962 static int list_session_agent_events(void)
963 {
964 int ret = CMD_SUCCESS, count, i;
965 struct lttng_event *events = NULL;
966
967 count = lttng_list_events(handle, "", &events);
968 if (count < 0) {
969 ret = CMD_ERROR;
970 ERR("%s", lttng_strerror(count));
971 goto error;
972 }
973
974 if (lttng_opt_mi) {
975 /* Mi print */
976 ret = mi_list_session_agent_events(events, count);
977 if (ret) {
978 ret = CMD_ERROR;
979 goto end;
980 }
981 } else {
982 /* Pretty print */
983 MSG("Events (Logger name):\n---------------------");
984 if (count == 0) {
985 MSG("%sNone\n", indent6);
986 goto end;
987 }
988
989 for (i = 0; i < count; i++) {
990 MSG("%s- %s%s (loglevel%s %s)", indent4, events[i].name,
991 enabled_string(events[i].enabled),
992 logleveltype_string(events[i].loglevel_type),
993 mi_lttng_loglevel_string(events[i].loglevel,
994 handle->domain.type));
995 }
996
997 MSG("");
998 }
999
1000 end:
1001 free(events);
1002 error:
1003 return ret;
1004 }
1005
1006 /*
1007 * Machine interface
1008 * print a list of event
1009 */
1010 static int mi_list_events(struct lttng_event *events, int count)
1011 {
1012 int ret, i;
1013
1014 /* Open events element */
1015 ret = mi_lttng_events_open(writer);
1016 if (ret) {
1017 goto end;
1018 }
1019
1020 for (i = 0; i < count; i++) {
1021 ret = mi_lttng_event(writer, &events[i], 0, handle->domain.type);
1022 if (ret) {
1023 goto end;
1024 }
1025 }
1026
1027 /* Close events element */
1028 ret = mi_lttng_writer_close_element(writer);
1029
1030 end:
1031 return ret;
1032 }
1033
1034 /*
1035 * List events of channel of session and domain.
1036 */
1037 static int list_events(const char *channel_name)
1038 {
1039 int ret = CMD_SUCCESS, count, i;
1040 struct lttng_event *events = NULL;
1041
1042 count = lttng_list_events(handle, channel_name, &events);
1043 if (count < 0) {
1044 ret = CMD_ERROR;
1045 ERR("%s", lttng_strerror(count));
1046 goto error;
1047 }
1048
1049 if (lttng_opt_mi) {
1050 /* Mi print */
1051 ret = mi_list_events(events, count);
1052 if (ret) {
1053 ret = CMD_ERROR;
1054 goto end;
1055 }
1056 } else {
1057 /* Pretty print */
1058 MSG("\n%sEvents:", indent4);
1059 if (count == 0) {
1060 MSG("%sNone\n", indent6);
1061 goto end;
1062 }
1063
1064 for (i = 0; i < count; i++) {
1065 print_events(&events[i]);
1066 }
1067
1068 MSG("");
1069 }
1070 end:
1071 free(events);
1072 error:
1073 return ret;
1074 }
1075
1076 /*
1077 * Pretty print channel
1078 */
1079 static void print_channel(struct lttng_channel *channel)
1080 {
1081 MSG("- %s:%s\n", channel->name, enabled_string(channel->enabled));
1082
1083 MSG("%sAttributes:", indent4);
1084 MSG("%soverwrite mode: %d", indent6, channel->attr.overwrite);
1085 MSG("%ssubbufers size: %" PRIu64, indent6, channel->attr.subbuf_size);
1086 MSG("%snumber of subbufers: %" PRIu64, indent6, channel->attr.num_subbuf);
1087 MSG("%sswitch timer interval: %u", indent6, channel->attr.switch_timer_interval);
1088 MSG("%sread timer interval: %u", indent6, channel->attr.read_timer_interval);
1089 MSG("%strace file count: %" PRIu64, indent6, channel->attr.tracefile_count);
1090 MSG("%strace file size (bytes): %" PRIu64, indent6, channel->attr.tracefile_size);
1091 switch (channel->attr.output) {
1092 case LTTNG_EVENT_SPLICE:
1093 MSG("%soutput: splice()", indent6);
1094 break;
1095 case LTTNG_EVENT_MMAP:
1096 MSG("%soutput: mmap()", indent6);
1097 break;
1098 }
1099 }
1100
1101 /*
1102 * Machine interface
1103 * Print a list of channel
1104 *
1105 */
1106 static int mi_list_channels(struct lttng_channel *channels, int count,
1107 const char *channel_name)
1108 {
1109 int i, ret;
1110 unsigned int chan_found = 0;
1111
1112 /* Open channels element */
1113 ret = mi_lttng_channels_open(writer);
1114 if (ret) {
1115 goto error;
1116 }
1117
1118 for (i = 0; i < count; i++) {
1119 if (channel_name != NULL) {
1120 if (strncmp(channels[i].name, channel_name, NAME_MAX) == 0) {
1121 chan_found = 1;
1122 } else {
1123 continue;
1124 }
1125 }
1126
1127 /* Write channel element and leave it open */
1128 ret = mi_lttng_channel(writer, &channels[i], 1);
1129 if (ret) {
1130 goto error;
1131 }
1132
1133 /* Listing events per channel */
1134 ret = list_events(channels[i].name);
1135 if (ret) {
1136 goto error;
1137 }
1138
1139 /* Closing the channel element we opened earlier */
1140 ret = mi_lttng_writer_close_element(writer);
1141 if (ret) {
1142 goto error;
1143 }
1144
1145 if (chan_found) {
1146 break;
1147 }
1148 }
1149
1150 /* Close channels element */
1151 ret = mi_lttng_writer_close_element(writer);
1152 if (ret) {
1153 goto error;
1154 }
1155
1156 error:
1157 return ret;
1158 }
1159
1160 /*
1161 * List channel(s) of session and domain.
1162 *
1163 * If channel_name is NULL, all channels are listed.
1164 */
1165 static int list_channels(const char *channel_name)
1166 {
1167 int count, i, ret = CMD_SUCCESS;
1168 unsigned int chan_found = 0;
1169 struct lttng_channel *channels = NULL;
1170
1171 DBG("Listing channel(s) (%s)", channel_name ? : "<all>");
1172
1173 count = lttng_list_channels(handle, &channels);
1174 if (count < 0) {
1175 switch (-count) {
1176 case LTTNG_ERR_KERN_CHAN_NOT_FOUND:
1177 if (lttng_opt_mi) {
1178 /* When printing mi this is not an error
1179 * but an empty channels element */
1180 count = 0;
1181 } else {
1182 ret = CMD_SUCCESS;
1183 WARN("No kernel channel");
1184 goto error_channels;
1185 }
1186 break;
1187 default:
1188 /* We had a real error */
1189 ret = CMD_ERROR;
1190 ERR("%s", lttng_strerror(count));
1191 goto error_channels;
1192 break;
1193 }
1194 }
1195
1196 if (lttng_opt_mi) {
1197 /* Mi print */
1198 ret = mi_list_channels(channels, count, channel_name);
1199 if (ret) {
1200 ret = CMD_ERROR;
1201 goto error;
1202 }
1203 } else {
1204 /* Pretty print */
1205 if (channel_name == NULL) {
1206 MSG("Channels:\n-------------");
1207 }
1208
1209 for (i = 0; i < count; i++) {
1210 if (channel_name != NULL) {
1211 if (strncmp(channels[i].name, channel_name, NAME_MAX) == 0) {
1212 chan_found = 1;
1213 } else {
1214 continue;
1215 }
1216 }
1217 print_channel(&channels[i]);
1218
1219 /* Listing events per channel */
1220 ret = list_events(channels[i].name);
1221 if (ret) {
1222 goto error;
1223 }
1224
1225 if (chan_found) {
1226 break;
1227 }
1228 }
1229
1230 if (!chan_found && channel_name != NULL) {
1231 ret = CMD_ERROR;
1232 ERR("Channel %s not found", channel_name);
1233 goto error;
1234 }
1235 }
1236 error:
1237 free(channels);
1238
1239 error_channels:
1240 return ret;
1241 }
1242
1243 /*
1244 * Machine interface
1245 * Find the session with session_name as name
1246 * and print his informations.
1247 */
1248 static int mi_list_session(const char *session_name,
1249 struct lttng_session *sessions, int count)
1250 {
1251 int ret, i;
1252 unsigned int session_found = 0;
1253
1254 if (session_name == NULL) {
1255 ret = -LTTNG_ERR_SESS_NOT_FOUND;
1256 goto end;
1257 }
1258
1259 for (i = 0; i < count; i++) {
1260 if (strncmp(sessions[i].name, session_name, NAME_MAX) == 0) {
1261 /* We need to leave it open to append other informations
1262 * like domain, channel, events etc.*/
1263 session_found = 1;
1264 ret = mi_lttng_session(writer, &sessions[i], 1);
1265 if (ret) {
1266 goto end;
1267 }
1268 break;
1269 }
1270 }
1271
1272 if (!session_found) {
1273 ERR("Session '%s' not found", session_name);
1274 ret = -LTTNG_ERR_SESS_NOT_FOUND;
1275 goto end;
1276 }
1277
1278 end:
1279 return ret;
1280 }
1281
1282 /*
1283 * Machine interface
1284 * List all availables session
1285 */
1286 static int mi_list_sessions(struct lttng_session *sessions, int count)
1287 {
1288 int ret, i;
1289
1290 /* Opening sessions element */
1291 ret = mi_lttng_sessions_open(writer);
1292 if (ret) {
1293 goto end;
1294 }
1295
1296 /* Listing sessions */
1297 for (i = 0; i < count; i++) {
1298 ret = mi_lttng_session(writer, &sessions[i], 0);
1299 if (ret) {
1300 goto end;
1301 }
1302 }
1303
1304 /* Closing sessions element */
1305 ret = mi_lttng_writer_close_element(writer);
1306 if (ret) {
1307 goto end;
1308 }
1309
1310 end:
1311 return ret;
1312 }
1313
1314 /*
1315 * List available tracing session. List only basic information.
1316 *
1317 * If session_name is NULL, all sessions are listed.
1318 */
1319 static int list_sessions(const char *session_name)
1320 {
1321 int ret = CMD_SUCCESS;
1322 int count, i;
1323 unsigned int session_found = 0;
1324 struct lttng_session *sessions;
1325
1326 count = lttng_list_sessions(&sessions);
1327 DBG("Session count %d", count);
1328 if (count < 0) {
1329 ret = CMD_ERROR;
1330 ERR("%s", lttng_strerror(count));
1331 goto end;
1332 }
1333
1334 if (lttng_opt_mi) {
1335 /* Mi */
1336 if (session_name == NULL) {
1337 /* List all session */
1338 ret = mi_list_sessions(sessions, count);
1339 } else {
1340 /* Note : this return an open session element */
1341 ret = mi_list_session(session_name, sessions, count);
1342 }
1343 if (ret) {
1344 ret = CMD_ERROR;
1345 goto error;
1346 }
1347 } else {
1348 /* Pretty print */
1349 if (count == 0) {
1350 MSG("Currently no available tracing session");
1351 goto end;
1352 }
1353
1354 if (session_name == NULL) {
1355 MSG("Available tracing sessions:");
1356 }
1357
1358
1359 for (i = 0; i < count; i++) {
1360 if (session_name != NULL) {
1361 if (strncmp(sessions[i].name, session_name, NAME_MAX) == 0) {
1362 session_found = 1;
1363 MSG("Tracing session %s: [%s%s]", session_name,
1364 active_string(sessions[i].enabled),
1365 snapshot_string(sessions[i].snapshot_mode));
1366 MSG("%sTrace path: %s\n", indent4, sessions[i].path);
1367 break;
1368 }
1369 } else {
1370 MSG(" %d) %s (%s) [%s%s]", i + 1,
1371 sessions[i].name, sessions[i].path,
1372 active_string(sessions[i].enabled),
1373 snapshot_string(sessions[i].snapshot_mode));
1374 MSG("%sTrace path: %s", indent4, sessions[i].path);
1375 MSG("%sLive timer interval (usec): %u\n", indent4,
1376 sessions[i].live_timer_interval);
1377 }
1378 }
1379
1380 if (!session_found && session_name != NULL) {
1381 ERR("Session '%s' not found", session_name);
1382 ret = CMD_ERROR;
1383 goto error;
1384 }
1385
1386 if (session_name == NULL) {
1387 MSG("\nUse lttng list <session_name> for more details");
1388 }
1389 }
1390
1391 error:
1392 free(sessions);
1393 end:
1394 return ret;
1395 }
1396
1397
1398 /*
1399 * Machine Interface
1400 * list available domain(s) for a session.
1401 */
1402 static int mi_list_domains(struct lttng_domain *domains, int count)
1403 {
1404 int i, ret;
1405 /* Open domains element */
1406 ret = mi_lttng_domains_open(writer);
1407 if (ret) {
1408 goto end;
1409 }
1410
1411 for (i = 0; i < count; i++) {
1412 ret = mi_lttng_domain(writer, &domains[i] , 0);
1413 if (ret) {
1414 goto end;
1415 }
1416 }
1417
1418 /* Closing domains element */
1419 ret = mi_lttng_writer_close_element(writer);
1420 if (ret) {
1421 goto end;
1422 }
1423 end:
1424 return ret;
1425 }
1426
1427 /*
1428 * List available domain(s) for a session.
1429 */
1430 static int list_domains(const char *session_name)
1431 {
1432 int i, count, ret = CMD_SUCCESS;
1433 struct lttng_domain *domains = NULL;
1434
1435
1436 count = lttng_list_domains(session_name, &domains);
1437 if (count < 0) {
1438 ret = CMD_ERROR;
1439 ERR("%s", lttng_strerror(count));
1440 goto end;
1441 }
1442
1443 if (lttng_opt_mi) {
1444 /* Mi output */
1445 ret = mi_list_domains(domains, count);
1446 if (ret) {
1447 ret = CMD_ERROR;
1448 goto error;
1449 }
1450 } else {
1451 /* Pretty print */
1452 MSG("Domains:\n-------------");
1453 if (count == 0) {
1454 MSG(" None");
1455 goto end;
1456 }
1457
1458 for (i = 0; i < count; i++) {
1459 switch (domains[i].type) {
1460 case LTTNG_DOMAIN_KERNEL:
1461 MSG(" - Kernel");
1462 break;
1463 case LTTNG_DOMAIN_UST:
1464 MSG(" - UST global");
1465 break;
1466 case LTTNG_DOMAIN_JUL:
1467 MSG(" - JUL (Java Util Logging)");
1468 break;
1469 case LTTNG_DOMAIN_LOG4J:
1470 MSG(" - LOG4j (Logging for Java)");
1471 break;
1472 default:
1473 break;
1474 }
1475 }
1476 }
1477
1478 error:
1479 free(domains);
1480
1481 end:
1482 return ret;
1483 }
1484
1485 /*
1486 * The 'list <options>' first level command
1487 */
1488 int cmd_list(int argc, const char **argv)
1489 {
1490 int opt, ret = CMD_SUCCESS;
1491 const char *session_name;
1492 static poptContext pc;
1493 struct lttng_domain domain;
1494 struct lttng_domain *domains = NULL;
1495
1496 memset(&domain, 0, sizeof(domain));
1497
1498 if (argc < 1) {
1499 usage(stderr);
1500 ret = CMD_ERROR;
1501 goto end;
1502 }
1503
1504 pc = poptGetContext(NULL, argc, argv, long_options, 0);
1505 poptReadDefaultConfig(pc, 0);
1506
1507 while ((opt = poptGetNextOpt(pc)) != -1) {
1508 switch (opt) {
1509 case OPT_HELP:
1510 usage(stdout);
1511 goto end;
1512 case OPT_USERSPACE:
1513 opt_userspace = 1;
1514 break;
1515 case OPT_LIST_OPTIONS:
1516 list_cmd_options(stdout, long_options);
1517 goto end;
1518 default:
1519 usage(stderr);
1520 ret = CMD_UNDEFINED;
1521 goto end;
1522 }
1523 }
1524
1525 /* Mi check */
1526 if (lttng_opt_mi) {
1527 writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi);
1528 if (!writer) {
1529 ret = CMD_ERROR;
1530 goto end;
1531 }
1532
1533 /* Open command element */
1534 ret = mi_lttng_writer_command_open(writer,
1535 mi_lttng_element_command_list);
1536 if (ret) {
1537 ret = CMD_ERROR;
1538 goto end;
1539 }
1540
1541 /* Open output element */
1542 ret = mi_lttng_writer_open_element(writer,
1543 mi_lttng_element_command_output);
1544 if (ret) {
1545 ret = CMD_ERROR;
1546 goto end;
1547 }
1548 }
1549
1550 /* Get session name (trailing argument) */
1551 session_name = poptGetArg(pc);
1552 DBG2("Session name: %s", session_name);
1553
1554 if (opt_kernel) {
1555 domain.type = LTTNG_DOMAIN_KERNEL;
1556 } else if (opt_userspace) {
1557 DBG2("Listing userspace global domain");
1558 domain.type = LTTNG_DOMAIN_UST;
1559 } else if (opt_jul) {
1560 DBG2("Listing JUL domain");
1561 domain.type = LTTNG_DOMAIN_JUL;
1562 } else if (opt_log4j) {
1563 domain.type = LTTNG_DOMAIN_LOG4J;
1564 }
1565
1566 if (!opt_kernel && opt_syscall) {
1567 WARN("--syscall will only work with the Kernel domain (-k)");
1568 ret = CMD_ERROR;
1569 goto end;
1570 }
1571
1572 if (opt_kernel || opt_userspace || opt_jul || opt_log4j) {
1573 handle = lttng_create_handle(session_name, &domain);
1574 if (handle == NULL) {
1575 ret = CMD_FATAL;
1576 goto end;
1577 }
1578 }
1579
1580 if (session_name == NULL) {
1581 if (!opt_kernel && !opt_userspace && !opt_jul && !opt_log4j) {
1582 ret = list_sessions(NULL);
1583 if (ret) {
1584 goto end;
1585 }
1586 }
1587 if (opt_kernel) {
1588 if (opt_syscall) {
1589 ret = list_syscalls();
1590 if (ret) {
1591 goto end;
1592 }
1593 } else {
1594 ret = list_kernel_events();
1595 if (ret) {
1596 goto end;
1597 }
1598 }
1599 }
1600 if (opt_userspace) {
1601 if (opt_fields) {
1602 ret = list_ust_event_fields();
1603 } else {
1604 ret = list_ust_events();
1605 }
1606 if (ret) {
1607 goto end;
1608 }
1609 }
1610 if (opt_jul || opt_log4j) {
1611 ret = list_agent_events();
1612 if (ret) {
1613 goto end;
1614 }
1615 }
1616 } else {
1617 /* List session attributes */
1618 if (lttng_opt_mi) {
1619 /* Open element sessions
1620 * Present for xml consistency */
1621 ret = mi_lttng_sessions_open(writer);
1622 if (ret) {
1623 goto end;
1624 }
1625 }
1626 /* MI: the ouptut of list_sessions is an unclosed session element */
1627 ret = list_sessions(session_name);
1628 if (ret) {
1629 goto end;
1630 }
1631
1632 /* Domain listing */
1633 if (opt_domain) {
1634 ret = list_domains(session_name);
1635 goto end;
1636 }
1637
1638 /* Channel listing */
1639 if (opt_kernel || opt_userspace) {
1640 if (lttng_opt_mi) {
1641 /* Add of domains and domain element for xml
1642 * consistency and validation
1643 */
1644 ret = mi_lttng_domains_open(writer);
1645 if (ret) {
1646 goto end;
1647 }
1648
1649 /* Open domain and leave it open for
1650 * nested channels printing */
1651 ret = mi_lttng_domain(writer, &domain, 1);
1652 if (ret) {
1653 goto end;
1654 }
1655
1656 }
1657
1658 ret = list_channels(opt_channel);
1659 if (ret) {
1660 goto end;
1661 }
1662
1663 if (lttng_opt_mi) {
1664 /* Close domain and domain element */
1665 ret = mi_lttng_close_multi_element(writer, 2);
1666 }
1667 if (ret) {
1668 goto end;
1669 }
1670
1671
1672 } else {
1673 int i, nb_domain;
1674
1675 /* We want all domain(s) */
1676 nb_domain = lttng_list_domains(session_name, &domains);
1677 if (nb_domain < 0) {
1678 ret = CMD_ERROR;
1679 ERR("%s", lttng_strerror(nb_domain));
1680 goto end;
1681 }
1682
1683 if (lttng_opt_mi) {
1684 ret = mi_lttng_domains_open(writer);
1685 if (ret) {
1686 ret = CMD_ERROR;
1687 goto end;
1688 }
1689 }
1690
1691 for (i = 0; i < nb_domain; i++) {
1692 switch (domains[i].type) {
1693 case LTTNG_DOMAIN_KERNEL:
1694 MSG("=== Domain: Kernel ===\n");
1695 break;
1696 case LTTNG_DOMAIN_UST:
1697 MSG("=== Domain: UST global ===\n");
1698 MSG("Buffer type: %s\n",
1699 domains[i].buf_type ==
1700 LTTNG_BUFFER_PER_PID ? "per PID" : "per UID");
1701 break;
1702 case LTTNG_DOMAIN_JUL:
1703 MSG("=== Domain: JUL (Java Util Logging) ===\n");
1704 break;
1705 case LTTNG_DOMAIN_LOG4J:
1706 MSG("=== Domain: LOG4j (Logging for Java) ===\n");
1707 break;
1708 default:
1709 MSG("=== Domain: Unimplemented ===\n");
1710 break;
1711 }
1712
1713 if (lttng_opt_mi) {
1714 ret = mi_lttng_domain(writer, &domains[i], 1);
1715 if (ret) {
1716 ret = CMD_ERROR;
1717 goto end;
1718 }
1719 }
1720
1721 /* Clean handle before creating a new one */
1722 if (handle) {
1723 lttng_destroy_handle(handle);
1724 }
1725
1726 handle = lttng_create_handle(session_name, &domains[i]);
1727 if (handle == NULL) {
1728 ret = CMD_FATAL;
1729 goto end;
1730 }
1731
1732 if (domains[i].type == LTTNG_DOMAIN_JUL ||
1733 domains[i].type == LTTNG_DOMAIN_LOG4J) {
1734 ret = list_session_agent_events();
1735 if (ret) {
1736 goto end;
1737 }
1738 continue;
1739 }
1740
1741 ret = list_channels(opt_channel);
1742 if (ret) {
1743 goto end;
1744 }
1745
1746 if (lttng_opt_mi) {
1747 /* Close domain element */
1748 ret = mi_lttng_writer_close_element(writer);
1749 if (ret) {
1750 ret = CMD_ERROR;
1751 goto end;
1752 }
1753 }
1754
1755 }
1756 if (lttng_opt_mi) {
1757 /* Close the domains, session and sessions element */
1758 ret = mi_lttng_close_multi_element(writer, 3);
1759 if (ret) {
1760 ret = CMD_ERROR;
1761 goto end;
1762 }
1763 }
1764 }
1765 }
1766
1767 /* Mi closing */
1768 if (lttng_opt_mi) {
1769 /* Close output element */
1770 ret = mi_lttng_writer_close_element(writer);
1771 if (ret) {
1772 ret = CMD_ERROR;
1773 goto end;
1774 }
1775
1776 /* Command element close */
1777 ret = mi_lttng_writer_command_close(writer);
1778 if (ret) {
1779 ret = CMD_ERROR;
1780 goto end;
1781 }
1782 }
1783 end:
1784 /* Mi clean-up */
1785 if (writer && mi_lttng_writer_destroy(writer)) {
1786 /* Preserve original error code */
1787 ret = ret ? ret : -LTTNG_ERR_MI_IO_FAIL;
1788 }
1789
1790 free(domains);
1791 if (handle) {
1792 lttng_destroy_handle(handle);
1793 }
1794
1795 poptFreeContext(pc);
1796 return ret;
1797 }
This page took 0.099383 seconds and 5 git commands to generate.