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