Fix: list_ust_events(): dangling pointer
[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 /* Open domains element */
577 ret = mi_lttng_domains_open(writer);
578 if (ret) {
579 goto end;
580 }
581
582 /* Write domain */
583 ret = mi_lttng_domain(writer, domain, 1);
584 if (ret) {
585 goto end;
586 }
587
588 /* Open pids element */
589 ret = mi_lttng_pids_open(writer);
590 if (ret) {
591 goto end;
592 }
593
594 for (i = 0; i < count; i++) {
595 if (cur_pid != fields[i].event.pid) {
596 if (pid_element_open) {
597 if (event_element_open) {
598
599 /* Close the previous field element and event. */
600 ret = mi_lttng_close_multi_element(writer, 2);
601 if (ret) {
602 goto end;
603 }
604 event_element_open = 0;
605 }
606 /* Close the previous events, pid element */
607 ret = mi_lttng_close_multi_element(writer, 2);
608 if (ret) {
609 goto end;
610 }
611 pid_element_open = 0;
612 }
613
614 cur_pid = fields[i].event.pid;
615 cmdline = get_cmdline_by_pid(cur_pid);
616 if (!pid_element_open) {
617 /* Open and write a pid element */
618 ret = mi_lttng_pid(writer, cur_pid, cmdline, 1);
619 if (ret) {
620 goto error;
621 }
622
623 /* Open events element */
624 ret = mi_lttng_events_open(writer);
625 if (ret) {
626 goto error;
627 }
628 pid_element_open = 1;
629 }
630 free(cmdline);
631 /* Wipe current event since we are about to print a new PID. */
632 memset(&cur_event, 0, sizeof(cur_event));
633 }
634
635 if (strcmp(cur_event.name, fields[i].event.name) != 0) {
636 if (event_element_open) {
637 /* Close the previous fields element and the previous event */
638 ret = mi_lttng_close_multi_element(writer, 2);
639 if (ret) {
640 goto end;
641 }
642 event_element_open = 0;
643 }
644
645 memcpy(&cur_event, &fields[i].event,
646 sizeof(cur_event));
647
648 if (!event_element_open) {
649 /* Open and write the event */
650 ret = mi_lttng_event(writer, &cur_event, 1,
651 handle->domain.type);
652 if (ret) {
653 goto end;
654 }
655
656 /* Open a fields element */
657 ret = mi_lttng_event_fields_open(writer);
658 if (ret) {
659 goto end;
660 }
661 event_element_open = 1;
662 }
663 }
664
665 /* Print the event_field */
666 ret = mi_lttng_event_field(writer, &fields[i]);
667 if (ret) {
668 goto end;
669 }
670 }
671
672 /* Close pids, domain, domains */
673 ret = mi_lttng_close_multi_element(writer, 3);
674 end:
675 return ret;
676 error:
677 free(cmdline);
678 return ret;
679 }
680
681 /*
682 * Ask session daemon for all user space tracepoint fields available.
683 */
684 static int list_ust_event_fields(void)
685 {
686 int i, size, ret = CMD_SUCCESS;
687 struct lttng_domain domain;
688 struct lttng_handle *handle;
689 struct lttng_event_field *event_field_list;
690 pid_t cur_pid = 0;
691 char *cmdline = NULL;
692
693 struct lttng_event cur_event;
694
695 memset(&domain, 0, sizeof(domain));
696 memset(&cur_event, 0, sizeof(cur_event));
697
698 DBG("Getting UST tracing event fields");
699
700 domain.type = LTTNG_DOMAIN_UST;
701
702 handle = lttng_create_handle(NULL, &domain);
703 if (handle == NULL) {
704 ret = CMD_ERROR;
705 goto end;
706 }
707
708 size = lttng_list_tracepoint_fields(handle, &event_field_list);
709 if (size < 0) {
710 ERR("Unable to list UST event fields: %s", lttng_strerror(size));
711 ret = CMD_ERROR;
712 goto end;
713 }
714
715 if (lttng_opt_mi) {
716 /* Mi print */
717 ret = mi_list_ust_event_fields(event_field_list, size, &domain);
718 if (ret) {
719 ret = CMD_ERROR;
720 goto error;
721 }
722 } else {
723 /* Pretty print */
724 MSG("UST events:\n-------------");
725
726 if (size == 0) {
727 MSG("None");
728 }
729
730 for (i = 0; i < size; i++) {
731 if (cur_pid != event_field_list[i].event.pid) {
732 cur_pid = event_field_list[i].event.pid;
733 cmdline = get_cmdline_by_pid(cur_pid);
734 if (cmdline == NULL) {
735 ret = CMD_ERROR;
736 goto error;
737 }
738 MSG("\nPID: %d - Name: %s", cur_pid, cmdline);
739 free(cmdline);
740 /* Wipe current event since we are about to print a new PID. */
741 memset(&cur_event, 0, sizeof(cur_event));
742 }
743 if (strcmp(cur_event.name, event_field_list[i].event.name) != 0) {
744 print_events(&event_field_list[i].event);
745 memcpy(&cur_event, &event_field_list[i].event,
746 sizeof(cur_event));
747 }
748 print_event_field(&event_field_list[i]);
749 }
750
751 MSG("");
752 }
753
754 error:
755 free(event_field_list);
756 end:
757 lttng_destroy_handle(handle);
758 return ret;
759 }
760
761 /*
762 * Machine interface
763 * Print a list of kernel events
764 */
765 static int mi_list_kernel_events(struct lttng_event *events, int count,
766 struct lttng_domain *domain)
767 {
768 int ret, i;
769
770 /* Open domains element */
771 ret = mi_lttng_domains_open(writer);
772 if (ret) {
773 goto end;
774 }
775
776 /* Write domain */
777 ret = mi_lttng_domain(writer, domain, 1);
778 if (ret) {
779 goto end;
780 }
781
782 /* Open events */
783 ret = mi_lttng_events_open(writer);
784 if (ret) {
785 goto end;
786 }
787
788 for (i = 0; i < count; i++) {
789 ret = mi_lttng_event(writer, &events[i], 0, handle->domain.type);
790 if (ret) {
791 goto end;
792 }
793 }
794
795 /* close events, domain and domains */
796 ret = mi_lttng_close_multi_element(writer, 3);
797 if (ret) {
798 goto end;
799 }
800
801 end:
802 return ret;
803 }
804
805 /*
806 * Ask for all trace events in the kernel
807 */
808 static int list_kernel_events(void)
809 {
810 int i, size, ret = CMD_SUCCESS;
811 struct lttng_domain domain;
812 struct lttng_handle *handle;
813 struct lttng_event *event_list;
814
815 memset(&domain, 0, sizeof(domain));
816
817 DBG("Getting kernel tracing events");
818
819 domain.type = LTTNG_DOMAIN_KERNEL;
820
821 handle = lttng_create_handle(NULL, &domain);
822 if (handle == NULL) {
823 ret = CMD_ERROR;
824 goto error;
825 }
826
827 size = lttng_list_tracepoints(handle, &event_list);
828 if (size < 0) {
829 ERR("Unable to list kernel events: %s", lttng_strerror(size));
830 lttng_destroy_handle(handle);
831 return CMD_ERROR;
832 }
833
834 if (lttng_opt_mi) {
835 /* Mi print */
836 ret = mi_list_kernel_events(event_list, size, &domain);
837 if (ret) {
838 ret = CMD_ERROR;
839 goto end;
840 }
841 } else {
842 MSG("Kernel events:\n-------------");
843
844 for (i = 0; i < size; i++) {
845 print_events(&event_list[i]);
846 }
847
848 MSG("");
849 }
850
851 end:
852 free(event_list);
853
854 lttng_destroy_handle(handle);
855 return ret;
856
857 error:
858 lttng_destroy_handle(handle);
859 return ret;
860 }
861
862 /*
863 * Machine interface
864 * Print a list of system calls.
865 */
866 static int mi_list_syscalls(struct lttng_event *events, int count)
867 {
868 int ret, i;
869
870 /* Open events */
871 ret = mi_lttng_events_open(writer);
872 if (ret) {
873 goto end;
874 }
875
876 for (i = 0; i < count; i++) {
877 ret = mi_lttng_event(writer, &events[i], 0, handle->domain.type);
878 if (ret) {
879 goto end;
880 }
881 }
882
883 /* Close events. */
884 ret = mi_lttng_writer_close_element(writer);
885 if (ret) {
886 goto end;
887 }
888
889 end:
890 return ret;
891 }
892
893 /*
894 * Ask for kernel system calls.
895 */
896 static int list_syscalls(void)
897 {
898 int i, size, ret = CMD_SUCCESS;
899 struct lttng_event *event_list;
900
901 DBG("Getting kernel system call events");
902
903 size = lttng_list_syscalls(&event_list);
904 if (size < 0) {
905 ERR("Unable to list system calls: %s", lttng_strerror(size));
906 ret = CMD_ERROR;
907 goto error;
908 }
909
910 if (lttng_opt_mi) {
911 /* Mi print */
912 ret = mi_list_syscalls(event_list, size);
913 if (ret) {
914 ret = CMD_ERROR;
915 goto end;
916 }
917 } else {
918 MSG("System calls:\n-------------");
919
920 for (i = 0; i < size; i++) {
921 print_events(&event_list[i]);
922 }
923
924 MSG("");
925 }
926
927 end:
928 free(event_list);
929 return ret;
930
931 error:
932 return ret;
933 }
934
935 /*
936 * Machine Interface
937 * Print a list of agent events
938 */
939 static int mi_list_session_agent_events(struct lttng_event *events, int count)
940 {
941 int ret, i;
942
943 /* Open events element */
944 ret = mi_lttng_events_open(writer);
945 if (ret) {
946 goto end;
947 }
948
949 for (i = 0; i < count; i++) {
950 ret = mi_lttng_event(writer, &events[i], 0, handle->domain.type);
951 if (ret) {
952 goto end;
953 }
954 }
955
956 /* Close events element */
957 ret = mi_lttng_writer_close_element(writer);
958
959 end:
960 return ret;
961 }
962
963 /*
964 * List agent events for a specific session using the handle.
965 *
966 * Return CMD_SUCCESS on success else a negative value.
967 */
968 static int list_session_agent_events(void)
969 {
970 int ret = CMD_SUCCESS, count, i;
971 struct lttng_event *events = NULL;
972
973 count = lttng_list_events(handle, "", &events);
974 if (count < 0) {
975 ret = CMD_ERROR;
976 ERR("%s", lttng_strerror(count));
977 goto error;
978 }
979
980 if (lttng_opt_mi) {
981 /* Mi print */
982 ret = mi_list_session_agent_events(events, count);
983 if (ret) {
984 ret = CMD_ERROR;
985 goto end;
986 }
987 } else {
988 /* Pretty print */
989 MSG("Events (Logger name):\n---------------------");
990 if (count == 0) {
991 MSG("%sNone\n", indent6);
992 goto end;
993 }
994
995 for (i = 0; i < count; i++) {
996 MSG("%s- %s%s (loglevel%s %s)", indent4, events[i].name,
997 enabled_string(events[i].enabled),
998 logleveltype_string(events[i].loglevel_type),
999 mi_lttng_loglevel_string(events[i].loglevel,
1000 handle->domain.type));
1001 }
1002
1003 MSG("");
1004 }
1005
1006 end:
1007 free(events);
1008 error:
1009 return ret;
1010 }
1011
1012 /*
1013 * Machine interface
1014 * print a list of event
1015 */
1016 static int mi_list_events(struct lttng_event *events, int count)
1017 {
1018 int ret, i;
1019
1020 /* Open events element */
1021 ret = mi_lttng_events_open(writer);
1022 if (ret) {
1023 goto end;
1024 }
1025
1026 for (i = 0; i < count; i++) {
1027 ret = mi_lttng_event(writer, &events[i], 0, handle->domain.type);
1028 if (ret) {
1029 goto end;
1030 }
1031 }
1032
1033 /* Close events element */
1034 ret = mi_lttng_writer_close_element(writer);
1035
1036 end:
1037 return ret;
1038 }
1039
1040 /*
1041 * List events of channel of session and domain.
1042 */
1043 static int list_events(const char *channel_name)
1044 {
1045 int ret = CMD_SUCCESS, count, i;
1046 struct lttng_event *events = NULL;
1047
1048 count = lttng_list_events(handle, channel_name, &events);
1049 if (count < 0) {
1050 ret = CMD_ERROR;
1051 ERR("%s", lttng_strerror(count));
1052 goto error;
1053 }
1054
1055 if (lttng_opt_mi) {
1056 /* Mi print */
1057 ret = mi_list_events(events, count);
1058 if (ret) {
1059 ret = CMD_ERROR;
1060 goto end;
1061 }
1062 } else {
1063 /* Pretty print */
1064 MSG("\n%sEvents:", indent4);
1065 if (count == 0) {
1066 MSG("%sNone\n", indent6);
1067 goto end;
1068 }
1069
1070 for (i = 0; i < count; i++) {
1071 print_events(&events[i]);
1072 }
1073
1074 MSG("");
1075 }
1076 end:
1077 free(events);
1078 error:
1079 return ret;
1080 }
1081
1082 /*
1083 * Pretty print channel
1084 */
1085 static void print_channel(struct lttng_channel *channel)
1086 {
1087 MSG("- %s:%s\n", channel->name, enabled_string(channel->enabled));
1088
1089 MSG("%sAttributes:", indent4);
1090 MSG("%soverwrite mode: %d", indent6, channel->attr.overwrite);
1091 MSG("%ssubbufers size: %" PRIu64, indent6, channel->attr.subbuf_size);
1092 MSG("%snumber of subbufers: %" PRIu64, indent6, channel->attr.num_subbuf);
1093 MSG("%sswitch timer interval: %u", indent6, channel->attr.switch_timer_interval);
1094 MSG("%sread timer interval: %u", indent6, channel->attr.read_timer_interval);
1095 MSG("%strace file count: %" PRIu64, indent6, channel->attr.tracefile_count);
1096 MSG("%strace file size (bytes): %" PRIu64, indent6, channel->attr.tracefile_size);
1097 switch (channel->attr.output) {
1098 case LTTNG_EVENT_SPLICE:
1099 MSG("%soutput: splice()", indent6);
1100 break;
1101 case LTTNG_EVENT_MMAP:
1102 MSG("%soutput: mmap()", indent6);
1103 break;
1104 }
1105 }
1106
1107 /*
1108 * Machine interface
1109 * Print a list of channel
1110 *
1111 */
1112 static int mi_list_channels(struct lttng_channel *channels, int count,
1113 const char *channel_name)
1114 {
1115 int i, ret;
1116 unsigned int chan_found = 0;
1117
1118 /* Open channels element */
1119 ret = mi_lttng_channels_open(writer);
1120 if (ret) {
1121 goto error;
1122 }
1123
1124 for (i = 0; i < count; i++) {
1125 if (channel_name != NULL) {
1126 if (strncmp(channels[i].name, channel_name, NAME_MAX) == 0) {
1127 chan_found = 1;
1128 } else {
1129 continue;
1130 }
1131 }
1132
1133 /* Write channel element and leave it open */
1134 ret = mi_lttng_channel(writer, &channels[i], 1);
1135 if (ret) {
1136 goto error;
1137 }
1138
1139 /* Listing events per channel */
1140 ret = list_events(channels[i].name);
1141 if (ret) {
1142 goto error;
1143 }
1144
1145 /* Closing the channel element we opened earlier */
1146 ret = mi_lttng_writer_close_element(writer);
1147 if (ret) {
1148 goto error;
1149 }
1150
1151 if (chan_found) {
1152 break;
1153 }
1154 }
1155
1156 /* Close channels element */
1157 ret = mi_lttng_writer_close_element(writer);
1158 if (ret) {
1159 goto error;
1160 }
1161
1162 error:
1163 return ret;
1164 }
1165
1166 /*
1167 * List channel(s) of session and domain.
1168 *
1169 * If channel_name is NULL, all channels are listed.
1170 */
1171 static int list_channels(const char *channel_name)
1172 {
1173 int count, i, ret = CMD_SUCCESS;
1174 unsigned int chan_found = 0;
1175 struct lttng_channel *channels = NULL;
1176
1177 DBG("Listing channel(s) (%s)", channel_name ? : "<all>");
1178
1179 count = lttng_list_channels(handle, &channels);
1180 if (count < 0) {
1181 switch (-count) {
1182 case LTTNG_ERR_KERN_CHAN_NOT_FOUND:
1183 if (lttng_opt_mi) {
1184 /* When printing mi this is not an error
1185 * but an empty channels element */
1186 count = 0;
1187 } else {
1188 ret = CMD_SUCCESS;
1189 WARN("No kernel channel");
1190 goto error_channels;
1191 }
1192 break;
1193 default:
1194 /* We had a real error */
1195 ret = CMD_ERROR;
1196 ERR("%s", lttng_strerror(count));
1197 goto error_channels;
1198 break;
1199 }
1200 }
1201
1202 if (lttng_opt_mi) {
1203 /* Mi print */
1204 ret = mi_list_channels(channels, count, channel_name);
1205 if (ret) {
1206 ret = CMD_ERROR;
1207 goto error;
1208 }
1209 } else {
1210 /* Pretty print */
1211 if (count) {
1212 MSG("Channels:\n-------------");
1213 }
1214
1215 for (i = 0; i < count; i++) {
1216 if (channel_name != NULL) {
1217 if (strncmp(channels[i].name, channel_name, NAME_MAX) == 0) {
1218 chan_found = 1;
1219 } else {
1220 continue;
1221 }
1222 }
1223 print_channel(&channels[i]);
1224
1225 /* Listing events per channel */
1226 ret = list_events(channels[i].name);
1227 if (ret) {
1228 goto error;
1229 }
1230
1231 if (chan_found) {
1232 break;
1233 }
1234 }
1235
1236 if (!chan_found && channel_name != NULL) {
1237 ret = CMD_ERROR;
1238 ERR("Channel %s not found", channel_name);
1239 goto error;
1240 }
1241 }
1242 error:
1243 free(channels);
1244
1245 error_channels:
1246 return ret;
1247 }
1248
1249 /*
1250 * Machine interface
1251 * Find the session with session_name as name
1252 * and print his informations.
1253 */
1254 static int mi_list_session(const char *session_name,
1255 struct lttng_session *sessions, int count)
1256 {
1257 int ret, i;
1258 unsigned int session_found = 0;
1259
1260 if (session_name == NULL) {
1261 ret = -LTTNG_ERR_SESS_NOT_FOUND;
1262 goto end;
1263 }
1264
1265 for (i = 0; i < count; i++) {
1266 if (strncmp(sessions[i].name, session_name, NAME_MAX) == 0) {
1267 /* We need to leave it open to append other informations
1268 * like domain, channel, events etc.*/
1269 session_found = 1;
1270 ret = mi_lttng_session(writer, &sessions[i], 1);
1271 if (ret) {
1272 goto end;
1273 }
1274 break;
1275 }
1276 }
1277
1278 if (!session_found) {
1279 ERR("Session '%s' not found", session_name);
1280 ret = -LTTNG_ERR_SESS_NOT_FOUND;
1281 goto end;
1282 }
1283
1284 end:
1285 return ret;
1286 }
1287
1288 /*
1289 * Machine interface
1290 * List all availables session
1291 */
1292 static int mi_list_sessions(struct lttng_session *sessions, int count)
1293 {
1294 int ret, i;
1295
1296 /* Opening sessions element */
1297 ret = mi_lttng_sessions_open(writer);
1298 if (ret) {
1299 goto end;
1300 }
1301
1302 /* Listing sessions */
1303 for (i = 0; i < count; i++) {
1304 ret = mi_lttng_session(writer, &sessions[i], 0);
1305 if (ret) {
1306 goto end;
1307 }
1308 }
1309
1310 /* Closing sessions element */
1311 ret = mi_lttng_writer_close_element(writer);
1312 if (ret) {
1313 goto end;
1314 }
1315
1316 end:
1317 return ret;
1318 }
1319
1320 /*
1321 * List available tracing session. List only basic information.
1322 *
1323 * If session_name is NULL, all sessions are listed.
1324 */
1325 static int list_sessions(const char *session_name)
1326 {
1327 int ret = CMD_SUCCESS;
1328 int count, i;
1329 unsigned int session_found = 0;
1330 struct lttng_session *sessions;
1331
1332 count = lttng_list_sessions(&sessions);
1333 DBG("Session count %d", count);
1334 if (count < 0) {
1335 ret = CMD_ERROR;
1336 ERR("%s", lttng_strerror(count));
1337 goto end;
1338 }
1339
1340 if (lttng_opt_mi) {
1341 /* Mi */
1342 if (session_name == NULL) {
1343 /* List all session */
1344 ret = mi_list_sessions(sessions, count);
1345 } else {
1346 /* Note : this return an open session element */
1347 ret = mi_list_session(session_name, sessions, count);
1348 }
1349 if (ret) {
1350 ret = CMD_ERROR;
1351 goto error;
1352 }
1353 } else {
1354 /* Pretty print */
1355 if (count == 0) {
1356 MSG("Currently no available tracing session");
1357 goto end;
1358 }
1359
1360 if (session_name == NULL) {
1361 MSG("Available tracing sessions:");
1362 }
1363
1364
1365 for (i = 0; i < count; i++) {
1366 if (session_name != NULL) {
1367 if (strncmp(sessions[i].name, session_name, NAME_MAX) == 0) {
1368 session_found = 1;
1369 MSG("Tracing session %s: [%s%s]", session_name,
1370 active_string(sessions[i].enabled),
1371 snapshot_string(sessions[i].snapshot_mode));
1372 MSG("%sTrace path: %s\n", indent4, sessions[i].path);
1373 break;
1374 }
1375 } else {
1376 MSG(" %d) %s (%s) [%s%s]", i + 1,
1377 sessions[i].name, sessions[i].path,
1378 active_string(sessions[i].enabled),
1379 snapshot_string(sessions[i].snapshot_mode));
1380 MSG("%sTrace path: %s", indent4, sessions[i].path);
1381 MSG("%sLive timer interval (usec): %u\n", indent4,
1382 sessions[i].live_timer_interval);
1383 }
1384 }
1385
1386 if (!session_found && session_name != NULL) {
1387 ERR("Session '%s' not found", session_name);
1388 ret = CMD_ERROR;
1389 goto error;
1390 }
1391
1392 if (session_name == NULL) {
1393 MSG("\nUse lttng list <session_name> for more details");
1394 }
1395 }
1396
1397 error:
1398 free(sessions);
1399 end:
1400 return ret;
1401 }
1402
1403
1404 /*
1405 * Machine Interface
1406 * list available domain(s) for a session.
1407 */
1408 static int mi_list_domains(struct lttng_domain *domains, int count)
1409 {
1410 int i, ret;
1411 /* Open domains element */
1412 ret = mi_lttng_domains_open(writer);
1413 if (ret) {
1414 goto end;
1415 }
1416
1417 for (i = 0; i < count; i++) {
1418 ret = mi_lttng_domain(writer, &domains[i] , 0);
1419 if (ret) {
1420 goto end;
1421 }
1422 }
1423
1424 /* Closing domains element */
1425 ret = mi_lttng_writer_close_element(writer);
1426 if (ret) {
1427 goto end;
1428 }
1429 end:
1430 return ret;
1431 }
1432
1433 /*
1434 * List available domain(s) for a session.
1435 */
1436 static int list_domains(const char *session_name)
1437 {
1438 int i, count, ret = CMD_SUCCESS;
1439 struct lttng_domain *domains = NULL;
1440
1441
1442 count = lttng_list_domains(session_name, &domains);
1443 if (count < 0) {
1444 ret = CMD_ERROR;
1445 ERR("%s", lttng_strerror(count));
1446 goto end;
1447 }
1448
1449 if (lttng_opt_mi) {
1450 /* Mi output */
1451 ret = mi_list_domains(domains, count);
1452 if (ret) {
1453 ret = CMD_ERROR;
1454 goto error;
1455 }
1456 } else {
1457 /* Pretty print */
1458 MSG("Domains:\n-------------");
1459 if (count == 0) {
1460 MSG(" None");
1461 goto end;
1462 }
1463
1464 for (i = 0; i < count; i++) {
1465 switch (domains[i].type) {
1466 case LTTNG_DOMAIN_KERNEL:
1467 MSG(" - Kernel");
1468 break;
1469 case LTTNG_DOMAIN_UST:
1470 MSG(" - UST global");
1471 break;
1472 case LTTNG_DOMAIN_JUL:
1473 MSG(" - JUL (Java Util Logging)");
1474 break;
1475 case LTTNG_DOMAIN_LOG4J:
1476 MSG(" - LOG4j (Logging for Java)");
1477 break;
1478 default:
1479 break;
1480 }
1481 }
1482 }
1483
1484 error:
1485 free(domains);
1486
1487 end:
1488 return ret;
1489 }
1490
1491 /*
1492 * The 'list <options>' first level command
1493 */
1494 int cmd_list(int argc, const char **argv)
1495 {
1496 int opt, ret = CMD_SUCCESS;
1497 const char *session_name;
1498 static poptContext pc;
1499 struct lttng_domain domain;
1500 struct lttng_domain *domains = NULL;
1501
1502 memset(&domain, 0, sizeof(domain));
1503
1504 if (argc < 1) {
1505 usage(stderr);
1506 ret = CMD_ERROR;
1507 goto end;
1508 }
1509
1510 pc = poptGetContext(NULL, argc, argv, long_options, 0);
1511 poptReadDefaultConfig(pc, 0);
1512
1513 while ((opt = poptGetNextOpt(pc)) != -1) {
1514 switch (opt) {
1515 case OPT_HELP:
1516 usage(stdout);
1517 goto end;
1518 case OPT_USERSPACE:
1519 opt_userspace = 1;
1520 break;
1521 case OPT_LIST_OPTIONS:
1522 list_cmd_options(stdout, long_options);
1523 goto end;
1524 default:
1525 usage(stderr);
1526 ret = CMD_UNDEFINED;
1527 goto end;
1528 }
1529 }
1530
1531 /* Mi check */
1532 if (lttng_opt_mi) {
1533 writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi);
1534 if (!writer) {
1535 ret = CMD_ERROR;
1536 goto end;
1537 }
1538
1539 /* Open command element */
1540 ret = mi_lttng_writer_command_open(writer,
1541 mi_lttng_element_command_list);
1542 if (ret) {
1543 ret = CMD_ERROR;
1544 goto end;
1545 }
1546
1547 /* Open output element */
1548 ret = mi_lttng_writer_open_element(writer,
1549 mi_lttng_element_command_output);
1550 if (ret) {
1551 ret = CMD_ERROR;
1552 goto end;
1553 }
1554 }
1555
1556 /* Get session name (trailing argument) */
1557 session_name = poptGetArg(pc);
1558 DBG2("Session name: %s", session_name);
1559
1560 if (opt_kernel) {
1561 domain.type = LTTNG_DOMAIN_KERNEL;
1562 } else if (opt_userspace) {
1563 DBG2("Listing userspace global domain");
1564 domain.type = LTTNG_DOMAIN_UST;
1565 } else if (opt_jul) {
1566 DBG2("Listing JUL domain");
1567 domain.type = LTTNG_DOMAIN_JUL;
1568 } else if (opt_log4j) {
1569 domain.type = LTTNG_DOMAIN_LOG4J;
1570 }
1571
1572 if (!opt_kernel && opt_syscall) {
1573 WARN("--syscall will only work with the Kernel domain (-k)");
1574 ret = CMD_ERROR;
1575 goto end;
1576 }
1577
1578 if (opt_kernel || opt_userspace || opt_jul || opt_log4j) {
1579 handle = lttng_create_handle(session_name, &domain);
1580 if (handle == NULL) {
1581 ret = CMD_FATAL;
1582 goto end;
1583 }
1584 }
1585
1586 if (session_name == NULL) {
1587 if (!opt_kernel && !opt_userspace && !opt_jul && !opt_log4j) {
1588 ret = list_sessions(NULL);
1589 if (ret) {
1590 goto end;
1591 }
1592 }
1593 if (opt_kernel) {
1594 if (opt_syscall) {
1595 ret = list_syscalls();
1596 if (ret) {
1597 goto end;
1598 }
1599 } else {
1600 ret = list_kernel_events();
1601 if (ret) {
1602 goto end;
1603 }
1604 }
1605 }
1606 if (opt_userspace) {
1607 if (opt_fields) {
1608 ret = list_ust_event_fields();
1609 } else {
1610 ret = list_ust_events();
1611 }
1612 if (ret) {
1613 goto end;
1614 }
1615 }
1616 if (opt_jul || opt_log4j) {
1617 ret = list_agent_events();
1618 if (ret) {
1619 goto end;
1620 }
1621 }
1622 } else {
1623 /* List session attributes */
1624 if (lttng_opt_mi) {
1625 /* Open element sessions
1626 * Present for xml consistency */
1627 ret = mi_lttng_sessions_open(writer);
1628 if (ret) {
1629 goto end;
1630 }
1631 }
1632 /* MI: the ouptut of list_sessions is an unclosed session element */
1633 ret = list_sessions(session_name);
1634 if (ret) {
1635 goto end;
1636 }
1637
1638 /* Domain listing */
1639 if (opt_domain) {
1640 ret = list_domains(session_name);
1641 goto end;
1642 }
1643
1644 /* Channel listing */
1645 if (opt_kernel || opt_userspace) {
1646 if (lttng_opt_mi) {
1647 /* Add of domains and domain element for xml
1648 * consistency and validation
1649 */
1650 ret = mi_lttng_domains_open(writer);
1651 if (ret) {
1652 goto end;
1653 }
1654
1655 /* Open domain and leave it open for
1656 * nested channels printing */
1657 ret = mi_lttng_domain(writer, &domain, 1);
1658 if (ret) {
1659 goto end;
1660 }
1661
1662 }
1663
1664 ret = list_channels(opt_channel);
1665 if (ret) {
1666 goto end;
1667 }
1668
1669 if (lttng_opt_mi) {
1670 /* Close domain and domain element */
1671 ret = mi_lttng_close_multi_element(writer, 2);
1672 }
1673 if (ret) {
1674 goto end;
1675 }
1676
1677
1678 } else {
1679 int i, nb_domain;
1680
1681 /* We want all domain(s) */
1682 nb_domain = lttng_list_domains(session_name, &domains);
1683 if (nb_domain < 0) {
1684 ret = CMD_ERROR;
1685 ERR("%s", lttng_strerror(nb_domain));
1686 goto end;
1687 }
1688
1689 if (lttng_opt_mi) {
1690 ret = mi_lttng_domains_open(writer);
1691 if (ret) {
1692 ret = CMD_ERROR;
1693 goto end;
1694 }
1695 }
1696
1697 for (i = 0; i < nb_domain; i++) {
1698 switch (domains[i].type) {
1699 case LTTNG_DOMAIN_KERNEL:
1700 MSG("=== Domain: Kernel ===\n");
1701 break;
1702 case LTTNG_DOMAIN_UST:
1703 MSG("=== Domain: UST global ===\n");
1704 MSG("Buffer type: %s\n",
1705 domains[i].buf_type ==
1706 LTTNG_BUFFER_PER_PID ? "per PID" : "per UID");
1707 break;
1708 case LTTNG_DOMAIN_JUL:
1709 MSG("=== Domain: JUL (Java Util Logging) ===\n");
1710 break;
1711 case LTTNG_DOMAIN_LOG4J:
1712 MSG("=== Domain: LOG4j (Logging for Java) ===\n");
1713 break;
1714 default:
1715 MSG("=== Domain: Unimplemented ===\n");
1716 break;
1717 }
1718
1719 if (lttng_opt_mi) {
1720 ret = mi_lttng_domain(writer, &domains[i], 1);
1721 if (ret) {
1722 ret = CMD_ERROR;
1723 goto end;
1724 }
1725 }
1726
1727 /* Clean handle before creating a new one */
1728 if (handle) {
1729 lttng_destroy_handle(handle);
1730 }
1731
1732 handle = lttng_create_handle(session_name, &domains[i]);
1733 if (handle == NULL) {
1734 ret = CMD_FATAL;
1735 goto end;
1736 }
1737
1738 if (domains[i].type == LTTNG_DOMAIN_JUL ||
1739 domains[i].type == LTTNG_DOMAIN_LOG4J) {
1740 ret = list_session_agent_events();
1741 if (ret) {
1742 goto end;
1743 }
1744 continue;
1745 }
1746
1747 ret = list_channels(opt_channel);
1748 if (ret) {
1749 goto end;
1750 }
1751
1752 if (lttng_opt_mi) {
1753 /* Close domain element */
1754 ret = mi_lttng_writer_close_element(writer);
1755 if (ret) {
1756 ret = CMD_ERROR;
1757 goto end;
1758 }
1759 }
1760
1761 }
1762 if (lttng_opt_mi) {
1763 /* Close the domains, session and sessions element */
1764 ret = mi_lttng_close_multi_element(writer, 3);
1765 if (ret) {
1766 ret = CMD_ERROR;
1767 goto end;
1768 }
1769 }
1770 }
1771 }
1772
1773 /* Mi closing */
1774 if (lttng_opt_mi) {
1775 /* Close output element */
1776 ret = mi_lttng_writer_close_element(writer);
1777 if (ret) {
1778 ret = CMD_ERROR;
1779 goto end;
1780 }
1781
1782 /* Command element close */
1783 ret = mi_lttng_writer_command_close(writer);
1784 if (ret) {
1785 ret = CMD_ERROR;
1786 goto end;
1787 }
1788 }
1789 end:
1790 /* Mi clean-up */
1791 if (writer && mi_lttng_writer_destroy(writer)) {
1792 /* Preserve original error code */
1793 ret = ret ? ret : -LTTNG_ERR_MI_IO_FAIL;
1794 }
1795
1796 free(domains);
1797 if (handle) {
1798 lttng_destroy_handle(handle);
1799 }
1800
1801 poptFreeContext(pc);
1802 return ret;
1803 }
This page took 0.097008 seconds and 4 git commands to generate.