Fix: check malloc return value
[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 "../command.h"
27
28 static int opt_userspace;
29 static int opt_kernel;
30 static char *opt_channel;
31 static int opt_domain;
32 static int opt_fields;
33 #if 0
34 /* Not implemented yet */
35 static char *opt_cmd_name;
36 static pid_t opt_pid;
37 #endif
38
39 const char *indent4 = " ";
40 const char *indent6 = " ";
41 const char *indent8 = " ";
42
43 enum {
44 OPT_HELP = 1,
45 OPT_USERSPACE,
46 OPT_LIST_OPTIONS,
47 };
48
49 static struct lttng_handle *handle;
50
51 static struct poptOption long_options[] = {
52 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
53 {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
54 {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
55 #if 0
56 /* Not implemented yet */
57 {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_cmd_name, OPT_USERSPACE, 0, 0},
58 {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0},
59 #else
60 {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0},
61 #endif
62 {"channel", 'c', POPT_ARG_STRING, &opt_channel, 0, 0, 0},
63 {"domain", 'd', POPT_ARG_VAL, &opt_domain, 1, 0, 0},
64 {"fields", 'f', POPT_ARG_VAL, &opt_fields, 1, 0, 0},
65 {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
66 {0, 0, 0, 0, 0, 0, 0}
67 };
68
69 /*
70 * usage
71 */
72 static void usage(FILE *ofp)
73 {
74 fprintf(ofp, "usage: lttng list [OPTIONS] [SESSION [SESSION OPTIONS]]\n");
75 fprintf(ofp, "\n");
76 fprintf(ofp, "With no arguments, list available tracing session(s)\n");
77 fprintf(ofp, "\n");
78 fprintf(ofp, "Without a session, -k lists available kernel events\n");
79 fprintf(ofp, "Without a session, -u lists available userspace events\n");
80 fprintf(ofp, "\n");
81 fprintf(ofp, " -h, --help Show this help\n");
82 fprintf(ofp, " --list-options Simple listing of options\n");
83 fprintf(ofp, " -k, --kernel Select kernel domain\n");
84 fprintf(ofp, " -u, --userspace Select user-space domain.\n");
85 fprintf(ofp, " -f, --fields List event fields.\n");
86 #if 0
87 fprintf(ofp, " -p, --pid PID List user-space events by PID\n");
88 #endif
89 fprintf(ofp, "\n");
90 fprintf(ofp, "Session Options:\n");
91 fprintf(ofp, " -c, --channel NAME List details of a channel\n");
92 fprintf(ofp, " -d, --domain List available domain(s)\n");
93 fprintf(ofp, "\n");
94 }
95
96 /*
97 * Get command line from /proc for a specific pid.
98 *
99 * On success, return an allocated string pointer to the proc cmdline.
100 * On error, return NULL.
101 */
102 static char *get_cmdline_by_pid(pid_t pid)
103 {
104 int ret;
105 FILE *fp;
106 char *cmdline = NULL;
107 char path[20]; /* Can't go bigger than /proc/65535/cmdline */
108
109 snprintf(path, sizeof(path), "/proc/%d/cmdline", pid);
110 fp = fopen(path, "r");
111 if (fp == NULL) {
112 goto end;
113 }
114
115 /* Caller must free() *cmdline */
116 cmdline = malloc(PATH_MAX);
117 if (!cmdline) {
118 perror("malloc cmdline");
119 goto end;
120 }
121 ret = fread(cmdline, 1, PATH_MAX, fp);
122 if (ret < 0) {
123 perror("fread proc list");
124 }
125 fclose(fp);
126
127 end:
128 return cmdline;
129 }
130
131 static
132 const char *active_string(int value)
133 {
134 switch (value) {
135 case 0: return "inactive";
136 case 1: return "active";
137 case -1: return "";
138 default: return NULL;
139 }
140 }
141
142 static const char *snapshot_string(int value)
143 {
144 switch (value) {
145 case 1:
146 return " snapshot";
147 default:
148 return "";
149 }
150 }
151
152 static
153 const char *enabled_string(int value)
154 {
155 switch (value) {
156 case 0: return " [disabled]";
157 case 1: return " [enabled]";
158 case -1: return "";
159 default: return NULL;
160 }
161 }
162
163 static
164 const char *filter_string(int value)
165 {
166 switch (value) {
167 case 1: return " [with filter]";
168 default: return "";
169 }
170 }
171
172 static const char *loglevel_string(int value)
173 {
174 switch (value) {
175 case -1:
176 return "";
177 case LTTNG_LOGLEVEL_EMERG:
178 return "TRACE_EMERG";
179 case LTTNG_LOGLEVEL_ALERT:
180 return "TRACE_ALERT";
181 case LTTNG_LOGLEVEL_CRIT:
182 return "TRACE_CRIT";
183 case LTTNG_LOGLEVEL_ERR:
184 return "TRACE_ERR";
185 case LTTNG_LOGLEVEL_WARNING:
186 return "TRACE_WARNING";
187 case LTTNG_LOGLEVEL_NOTICE:
188 return "TRACE_NOTICE";
189 case LTTNG_LOGLEVEL_INFO:
190 return "TRACE_INFO";
191 case LTTNG_LOGLEVEL_DEBUG_SYSTEM:
192 return "TRACE_DEBUG_SYSTEM";
193 case LTTNG_LOGLEVEL_DEBUG_PROGRAM:
194 return "TRACE_DEBUG_PROGRAM";
195 case LTTNG_LOGLEVEL_DEBUG_PROCESS:
196 return "TRACE_DEBUG_PROCESS";
197 case LTTNG_LOGLEVEL_DEBUG_MODULE:
198 return "TRACE_DEBUG_MODULE";
199 case LTTNG_LOGLEVEL_DEBUG_UNIT:
200 return "TRACE_DEBUG_UNIT";
201 case LTTNG_LOGLEVEL_DEBUG_FUNCTION:
202 return "TRACE_DEBUG_FUNCTION";
203 case LTTNG_LOGLEVEL_DEBUG_LINE:
204 return "TRACE_DEBUG_LINE";
205 case LTTNG_LOGLEVEL_DEBUG:
206 return "TRACE_DEBUG";
207 default:
208 return "<<UNKNOWN>>";
209 }
210 }
211
212 /*
213 * Pretty print single event.
214 */
215 static void print_events(struct lttng_event *event)
216 {
217 switch (event->type) {
218 case LTTNG_EVENT_TRACEPOINT:
219 {
220 if (event->loglevel != -1) {
221 MSG("%s%s (loglevel: %s (%d)) (type: tracepoint)%s%s",
222 indent6,
223 event->name,
224 loglevel_string(event->loglevel),
225 event->loglevel,
226 enabled_string(event->enabled),
227 filter_string(event->filter));
228 } else {
229 MSG("%s%s (type: tracepoint)%s%s",
230 indent6,
231 event->name,
232 enabled_string(event->enabled),
233 filter_string(event->filter));
234 }
235 break;
236 }
237 case LTTNG_EVENT_FUNCTION:
238 MSG("%s%s (type: function)%s%s", indent6,
239 event->name, enabled_string(event->enabled),
240 filter_string(event->filter));
241 if (event->attr.probe.addr != 0) {
242 MSG("%saddr: 0x%" PRIx64, indent8, event->attr.probe.addr);
243 } else {
244 MSG("%soffset: 0x%" PRIx64, indent8, event->attr.probe.offset);
245 MSG("%ssymbol: %s", indent8, event->attr.probe.symbol_name);
246 }
247 break;
248 case LTTNG_EVENT_PROBE:
249 MSG("%s%s (type: probe)%s%s", indent6,
250 event->name, enabled_string(event->enabled),
251 filter_string(event->filter));
252 if (event->attr.probe.addr != 0) {
253 MSG("%saddr: 0x%" PRIx64, indent8, event->attr.probe.addr);
254 } else {
255 MSG("%soffset: 0x%" PRIx64, indent8, event->attr.probe.offset);
256 MSG("%ssymbol: %s", indent8, event->attr.probe.symbol_name);
257 }
258 break;
259 case LTTNG_EVENT_FUNCTION_ENTRY:
260 MSG("%s%s (type: function)%s%s", indent6,
261 event->name, enabled_string(event->enabled),
262 filter_string(event->filter));
263 MSG("%ssymbol: \"%s\"", indent8, event->attr.ftrace.symbol_name);
264 break;
265 case LTTNG_EVENT_SYSCALL:
266 MSG("%ssyscalls (type: syscall)%s%s", indent6,
267 enabled_string(event->enabled),
268 filter_string(event->filter));
269 break;
270 case LTTNG_EVENT_NOOP:
271 MSG("%s (type: noop)%s%s", indent6,
272 enabled_string(event->enabled),
273 filter_string(event->filter));
274 break;
275 case LTTNG_EVENT_ALL:
276 /* We should never have "all" events in list. */
277 assert(0);
278 break;
279 }
280 }
281
282 static const char *field_type(struct lttng_event_field *field)
283 {
284 switch(field->type) {
285 case LTTNG_EVENT_FIELD_INTEGER:
286 return "integer";
287 case LTTNG_EVENT_FIELD_ENUM:
288 return "enum";
289 case LTTNG_EVENT_FIELD_FLOAT:
290 return "float";
291 case LTTNG_EVENT_FIELD_STRING:
292 return "string";
293 case LTTNG_EVENT_FIELD_OTHER:
294 default: /* fall-through */
295 return "unknown";
296 }
297 }
298
299 /*
300 * Pretty print single event fields.
301 */
302 static void print_event_field(struct lttng_event_field *field)
303 {
304 if (!field->field_name[0]) {
305 return;
306 }
307 MSG("%sfield: %s (%s)%s", indent8, field->field_name,
308 field_type(field), field->nowrite ? " [no write]" : "");
309 }
310
311 /*
312 * Ask session daemon for all user space tracepoints available.
313 */
314 static int list_ust_events(void)
315 {
316 int i, size;
317 struct lttng_domain domain;
318 struct lttng_handle *handle;
319 struct lttng_event *event_list;
320 pid_t cur_pid = 0;
321 char *cmdline = NULL;
322
323 memset(&domain, 0, sizeof(domain));
324
325 DBG("Getting UST tracing events");
326
327 domain.type = LTTNG_DOMAIN_UST;
328
329 handle = lttng_create_handle(NULL, &domain);
330 if (handle == NULL) {
331 goto error;
332 }
333
334 size = lttng_list_tracepoints(handle, &event_list);
335 if (size < 0) {
336 ERR("Unable to list UST events: %s", lttng_strerror(size));
337 lttng_destroy_handle(handle);
338 return size;
339 }
340
341 MSG("UST events:\n-------------");
342
343 if (size == 0) {
344 MSG("None");
345 }
346
347 for (i = 0; i < size; i++) {
348 if (cur_pid != event_list[i].pid) {
349 cur_pid = event_list[i].pid;
350 cmdline = get_cmdline_by_pid(cur_pid);
351 MSG("\nPID: %d - Name: %s", cur_pid, cmdline);
352 free(cmdline);
353 }
354 print_events(&event_list[i]);
355 }
356
357 MSG("");
358
359 free(event_list);
360 lttng_destroy_handle(handle);
361
362 return CMD_SUCCESS;
363
364 error:
365 lttng_destroy_handle(handle);
366 return -1;
367 }
368
369 /*
370 * Ask session daemon for all user space tracepoint fields available.
371 */
372 static int list_ust_event_fields(void)
373 {
374 int i, size;
375 struct lttng_domain domain;
376 struct lttng_handle *handle;
377 struct lttng_event_field *event_field_list;
378 pid_t cur_pid = 0;
379 char *cmdline = NULL;
380
381 struct lttng_event cur_event;
382
383 memset(&domain, 0, sizeof(domain));
384 memset(&cur_event, 0, sizeof(cur_event));
385
386 DBG("Getting UST tracing event fields");
387
388 domain.type = LTTNG_DOMAIN_UST;
389
390 handle = lttng_create_handle(NULL, &domain);
391 if (handle == NULL) {
392 goto error;
393 }
394
395 size = lttng_list_tracepoint_fields(handle, &event_field_list);
396 if (size < 0) {
397 ERR("Unable to list UST event fields: %s", lttng_strerror(size));
398 lttng_destroy_handle(handle);
399 return size;
400 }
401
402 MSG("UST events:\n-------------");
403
404 if (size == 0) {
405 MSG("None");
406 }
407
408 for (i = 0; i < size; i++) {
409 if (cur_pid != event_field_list[i].event.pid) {
410 cur_pid = event_field_list[i].event.pid;
411 cmdline = get_cmdline_by_pid(cur_pid);
412 MSG("\nPID: %d - Name: %s", cur_pid, cmdline);
413 free(cmdline);
414 /* Wipe current event since we are about to print a new PID. */
415 memset(&cur_event, 0, sizeof(cur_event));
416 }
417 if (strcmp(cur_event.name, event_field_list[i].event.name) != 0) {
418 print_events(&event_field_list[i].event);
419 memcpy(&cur_event, &event_field_list[i].event,
420 sizeof(cur_event));
421 }
422 print_event_field(&event_field_list[i]);
423 }
424
425 MSG("");
426
427 free(event_field_list);
428 lttng_destroy_handle(handle);
429
430 return CMD_SUCCESS;
431
432 error:
433 lttng_destroy_handle(handle);
434 return -1;
435 }
436
437 /*
438 * Ask for all trace events in the kernel and pretty print them.
439 */
440 static int list_kernel_events(void)
441 {
442 int i, size;
443 struct lttng_domain domain;
444 struct lttng_handle *handle;
445 struct lttng_event *event_list;
446
447 memset(&domain, 0, sizeof(domain));
448
449 DBG("Getting kernel tracing events");
450
451 domain.type = LTTNG_DOMAIN_KERNEL;
452
453 handle = lttng_create_handle(NULL, &domain);
454 if (handle == NULL) {
455 goto error;
456 }
457
458 size = lttng_list_tracepoints(handle, &event_list);
459 if (size < 0) {
460 ERR("Unable to list kernel events: %s", lttng_strerror(size));
461 lttng_destroy_handle(handle);
462 return size;
463 }
464
465 MSG("Kernel events:\n-------------");
466
467 for (i = 0; i < size; i++) {
468 print_events(&event_list[i]);
469 }
470
471 MSG("");
472
473 free(event_list);
474
475 lttng_destroy_handle(handle);
476 return CMD_SUCCESS;
477
478 error:
479 lttng_destroy_handle(handle);
480 return -1;
481 }
482
483 /*
484 * List events of channel of session and domain.
485 */
486 static int list_events(const char *channel_name)
487 {
488 int ret, count, i;
489 struct lttng_event *events = NULL;
490
491 count = lttng_list_events(handle, channel_name, &events);
492 if (count < 0) {
493 ret = count;
494 ERR("%s", lttng_strerror(ret));
495 goto error;
496 }
497
498 MSG("\n%sEvents:", indent4);
499 if (count == 0) {
500 MSG("%sNone\n", indent6);
501 goto end;
502 }
503
504 for (i = 0; i < count; i++) {
505 print_events(&events[i]);
506 }
507
508 MSG("");
509
510 end:
511 free(events);
512 ret = CMD_SUCCESS;
513
514 error:
515 return ret;
516 }
517
518 /*
519 * Pretty print channel
520 */
521 static void print_channel(struct lttng_channel *channel)
522 {
523 MSG("- %s:%s\n", channel->name, enabled_string(channel->enabled));
524
525 MSG("%sAttributes:", indent4);
526 MSG("%soverwrite mode: %d", indent6, channel->attr.overwrite);
527 MSG("%ssubbufers size: %" PRIu64, indent6, channel->attr.subbuf_size);
528 MSG("%snumber of subbufers: %" PRIu64, indent6, channel->attr.num_subbuf);
529 MSG("%sswitch timer interval: %u", indent6, channel->attr.switch_timer_interval);
530 MSG("%sread timer interval: %u", indent6, channel->attr.read_timer_interval);
531 switch (channel->attr.output) {
532 case LTTNG_EVENT_SPLICE:
533 MSG("%soutput: splice()", indent6);
534 break;
535 case LTTNG_EVENT_MMAP:
536 MSG("%soutput: mmap()", indent6);
537 break;
538 }
539 }
540
541 /*
542 * List channel(s) of session and domain.
543 *
544 * If channel_name is NULL, all channels are listed.
545 */
546 static int list_channels(const char *channel_name)
547 {
548 int count, i, ret = CMD_SUCCESS;
549 unsigned int chan_found = 0;
550 struct lttng_channel *channels = NULL;
551
552 DBG("Listing channel(s) (%s)", channel_name ? : "<all>");
553
554 count = lttng_list_channels(handle, &channels);
555 if (count < 0) {
556 switch (-count) {
557 case LTTNG_ERR_KERN_CHAN_NOT_FOUND:
558 ret = CMD_SUCCESS;
559 WARN("No kernel channel");
560 break;
561 default:
562 /* We had a real error */
563 ret = count;
564 ERR("%s", lttng_strerror(ret));
565 break;
566 }
567 goto error_channels;
568 }
569
570 if (channel_name == NULL) {
571 MSG("Channels:\n-------------");
572 }
573
574 for (i = 0; i < count; i++) {
575 if (channel_name != NULL) {
576 if (strncmp(channels[i].name, channel_name, NAME_MAX) == 0) {
577 chan_found = 1;
578 } else {
579 continue;
580 }
581 }
582 print_channel(&channels[i]);
583
584 /* Listing events per channel */
585 ret = list_events(channels[i].name);
586 if (ret < 0) {
587 ERR("%s", lttng_strerror(ret));
588 }
589
590 if (chan_found) {
591 break;
592 }
593 }
594
595 if (!chan_found && channel_name != NULL) {
596 ERR("Channel %s not found", channel_name);
597 goto error;
598 }
599
600 ret = CMD_SUCCESS;
601
602 error:
603 free(channels);
604
605 error_channels:
606 return ret;
607 }
608
609 /*
610 * List available tracing session. List only basic information.
611 *
612 * If session_name is NULL, all sessions are listed.
613 */
614 static int list_sessions(const char *session_name)
615 {
616 int ret, count, i;
617 unsigned int session_found = 0;
618 struct lttng_session *sessions;
619
620 count = lttng_list_sessions(&sessions);
621 DBG("Session count %d", count);
622 if (count < 0) {
623 ret = count;
624 ERR("%s", lttng_strerror(ret));
625 goto error;
626 } else if (count == 0) {
627 MSG("Currently no available tracing session");
628 goto end;
629 }
630
631 if (session_name == NULL) {
632 MSG("Available tracing sessions:");
633 }
634
635 for (i = 0; i < count; i++) {
636 if (session_name != NULL) {
637 if (strncmp(sessions[i].name, session_name, NAME_MAX) == 0) {
638 session_found = 1;
639 MSG("Tracing session %s: [%s%s]", session_name,
640 active_string(sessions[i].enabled),
641 snapshot_string(sessions[i].snapshot_mode));
642 MSG("%sTrace path: %s\n", indent4, sessions[i].path);
643 break;
644 }
645 } else {
646 MSG(" %d) %s (%s) [%s%s]", i + 1, sessions[i].name, sessions[i].path,
647 active_string(sessions[i].enabled),
648 snapshot_string(sessions[i].snapshot_mode));
649 }
650 }
651
652 free(sessions);
653
654 if (!session_found && session_name != NULL) {
655 ERR("Session '%s' not found", session_name);
656 ret = CMD_ERROR;
657 goto error;
658 }
659
660 if (session_name == NULL) {
661 MSG("\nUse lttng list <session_name> for more details");
662 }
663
664 end:
665 return CMD_SUCCESS;
666
667 error:
668 return ret;
669 }
670
671 /*
672 * List available domain(s) for a session.
673 */
674 static int list_domains(const char *session_name)
675 {
676 int i, count, ret = CMD_SUCCESS;
677 struct lttng_domain *domains = NULL;
678
679 MSG("Domains:\n-------------");
680
681 count = lttng_list_domains(session_name, &domains);
682 if (count < 0) {
683 ret = count;
684 ERR("%s", lttng_strerror(ret));
685 goto error;
686 } else if (count == 0) {
687 MSG(" None");
688 goto end;
689 }
690
691 for (i = 0; i < count; i++) {
692 switch (domains[i].type) {
693 case LTTNG_DOMAIN_KERNEL:
694 MSG(" - Kernel");
695 break;
696 case LTTNG_DOMAIN_UST:
697 MSG(" - UST global");
698 break;
699 default:
700 break;
701 }
702 }
703
704 end:
705 free(domains);
706
707 error:
708 return ret;
709 }
710
711 /*
712 * The 'list <options>' first level command
713 */
714 int cmd_list(int argc, const char **argv)
715 {
716 int opt, ret = CMD_SUCCESS;
717 const char *session_name;
718 static poptContext pc;
719 struct lttng_domain domain;
720 struct lttng_domain *domains = NULL;
721
722 memset(&domain, 0, sizeof(domain));
723
724 if (argc < 1) {
725 usage(stderr);
726 ret = CMD_ERROR;
727 goto end;
728 }
729
730 pc = poptGetContext(NULL, argc, argv, long_options, 0);
731 poptReadDefaultConfig(pc, 0);
732
733 while ((opt = poptGetNextOpt(pc)) != -1) {
734 switch (opt) {
735 case OPT_HELP:
736 usage(stdout);
737 goto end;
738 case OPT_USERSPACE:
739 opt_userspace = 1;
740 break;
741 case OPT_LIST_OPTIONS:
742 list_cmd_options(stdout, long_options);
743 goto end;
744 default:
745 usage(stderr);
746 ret = CMD_UNDEFINED;
747 goto end;
748 }
749 }
750
751 /* Get session name (trailing argument) */
752 session_name = poptGetArg(pc);
753 DBG2("Session name: %s", session_name);
754
755 if (opt_kernel) {
756 domain.type = LTTNG_DOMAIN_KERNEL;
757 } else if (opt_userspace) {
758 DBG2("Listing userspace global domain");
759 domain.type = LTTNG_DOMAIN_UST;
760 }
761
762 if (opt_kernel || opt_userspace) {
763 handle = lttng_create_handle(session_name, &domain);
764 if (handle == NULL) {
765 ret = CMD_FATAL;
766 goto end;
767 }
768 }
769
770 if (session_name == NULL) {
771 if (!opt_kernel && !opt_userspace) {
772 ret = list_sessions(NULL);
773 if (ret != 0) {
774 goto end;
775 }
776 }
777 if (opt_kernel) {
778 ret = list_kernel_events();
779 if (ret < 0) {
780 ret = CMD_ERROR;
781 goto end;
782 }
783 }
784 if (opt_userspace) {
785 if (opt_fields) {
786 ret = list_ust_event_fields();
787 } else {
788 ret = list_ust_events();
789 }
790 if (ret < 0) {
791 ret = CMD_ERROR;
792 goto end;
793 }
794 }
795 } else {
796 /* List session attributes */
797 ret = list_sessions(session_name);
798 if (ret != 0) {
799 goto end;
800 }
801
802 /* Domain listing */
803 if (opt_domain) {
804 ret = list_domains(session_name);
805 goto end;
806 }
807
808 if (opt_kernel || opt_userspace) {
809 /* Channel listing */
810 ret = list_channels(opt_channel);
811 if (ret < 0) {
812 goto end;
813 }
814 } else {
815 int i, nb_domain;
816
817 /* We want all domain(s) */
818 nb_domain = lttng_list_domains(session_name, &domains);
819 if (nb_domain < 0) {
820 ret = nb_domain;
821 ERR("%s", lttng_strerror(ret));
822 goto end;
823 }
824
825 for (i = 0; i < nb_domain; i++) {
826 switch (domains[i].type) {
827 case LTTNG_DOMAIN_KERNEL:
828 MSG("=== Domain: Kernel ===\n");
829 break;
830 case LTTNG_DOMAIN_UST:
831 MSG("=== Domain: UST global ===\n");
832 MSG("Buffer type: %s\n",
833 domains[i].buf_type ==
834 LTTNG_BUFFER_PER_PID ? "per PID" : "per UID");
835 break;
836 default:
837 MSG("=== Domain: Unimplemented ===\n");
838 break;
839 }
840
841 /* Clean handle before creating a new one */
842 if (handle) {
843 lttng_destroy_handle(handle);
844 }
845
846 handle = lttng_create_handle(session_name, &domains[i]);
847 if (handle == NULL) {
848 ret = CMD_FATAL;
849 goto end;
850 }
851
852 ret = list_channels(opt_channel);
853 if (ret < 0) {
854 goto end;
855 }
856 }
857 }
858 }
859
860 end:
861 free(domains);
862 if (handle) {
863 lttng_destroy_handle(handle);
864 }
865
866 poptFreeContext(pc);
867 return ret;
868 }
This page took 0.046666 seconds and 4 git commands to generate.