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