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