+ /* Open domains element */
+ ret = mi_lttng_domains_open(writer);
+ if (ret) {
+ goto end;
+ }
+
+ /* Write domain */
+ ret = mi_lttng_domain(writer, domain, 1);
+ if (ret) {
+ goto end;
+ }
+
+ /* Open events */
+ ret = mi_lttng_events_open(writer);
+ if (ret) {
+ goto end;
+ }
+
+ for (i = 0; i < count; i++) {
+ ret = mi_lttng_event(writer, &events[i], 0, handle->domain.type);
+ if (ret) {
+ goto end;
+ }
+ }
+
+ /* close events, domain and domains */
+ ret = mi_lttng_close_multi_element(writer, 3);
+ if (ret) {
+ goto end;
+ }
+
+end:
+ return ret;
+}
+
+/*
+ * Ask for all trace events in the kernel
+ */
+static int list_kernel_events(void)
+{
+ int i, size, ret = CMD_SUCCESS;
+ struct lttng_domain domain;
+ struct lttng_handle *handle;
+ struct lttng_event *event_list;
+
+ memset(&domain, 0, sizeof(domain));
+
+ DBG("Getting kernel tracing events");
+
+ domain.type = LTTNG_DOMAIN_KERNEL;
+
+ handle = lttng_create_handle(NULL, &domain);
+ if (handle == NULL) {
+ ret = CMD_ERROR;
+ goto error;
+ }
+
+ size = lttng_list_tracepoints(handle, &event_list);
+ if (size < 0) {
+ ERR("Unable to list kernel events: %s", lttng_strerror(size));
+ lttng_destroy_handle(handle);
+ return CMD_ERROR;
+ }
+
+ if (lttng_opt_mi) {
+ /* Mi print */
+ ret = mi_list_kernel_events(event_list, size, &domain);
+ if (ret) {
+ ret = CMD_ERROR;
+ goto end;
+ }
+ } else {
+ MSG("Kernel events:\n-------------");
+
+ for (i = 0; i < size; i++) {
+ print_events(&event_list[i]);
+ }
+
+ MSG("");
+ }
+
+end:
+ free(event_list);
+
+ lttng_destroy_handle(handle);
+ return ret;
+
+error:
+ lttng_destroy_handle(handle);
+ return ret;
+}
+
+/*
+ * Machine interface
+ * Print a list of system calls.
+ */
+static int mi_list_syscalls(struct lttng_event *events, int count)
+{
+ int ret, i;
+
+ /* Open events */
+ ret = mi_lttng_events_open(writer);
+ if (ret) {
+ goto end;
+ }
+
+ for (i = 0; i < count; i++) {
+ ret = mi_lttng_event(writer, &events[i], 0, handle->domain.type);
+ if (ret) {
+ goto end;
+ }
+ }
+
+ /* Close events. */
+ ret = mi_lttng_writer_close_element(writer);
+ if (ret) {
+ goto end;
+ }
+
+end:
+ return ret;
+}
+
+/*
+ * Ask for kernel system calls.
+ */
+static int list_syscalls(void)
+{
+ int i, size, ret = CMD_SUCCESS;
+ struct lttng_event *event_list;
+
+ DBG("Getting kernel system call events");
+
+ size = lttng_list_syscalls(&event_list);
+ if (size < 0) {
+ ERR("Unable to list system calls: %s", lttng_strerror(size));
+ ret = CMD_ERROR;
+ goto error;
+ }
+
+ if (lttng_opt_mi) {
+ /* Mi print */
+ ret = mi_list_syscalls(event_list, size);
+ if (ret) {
+ ret = CMD_ERROR;
+ goto end;
+ }
+ } else {
+ MSG("System calls:\n-------------");
+
+ for (i = 0; i < size; i++) {
+ print_events(&event_list[i]);
+ }
+
+ MSG("");
+ }
+
+end:
+ free(event_list);
+ return ret;
+
+error:
+ return ret;
+}
+
+/*
+ * Machine Interface
+ * Print a list of agent events
+ */
+static int mi_list_session_agent_events(struct lttng_event *events, int count)
+{
+ int ret, i;
+
+ /* Open events element */
+ ret = mi_lttng_events_open(writer);
+ if (ret) {
+ goto end;
+ }
+
+ for (i = 0; i < count; i++) {
+ ret = mi_lttng_event(writer, &events[i], 0, handle->domain.type);
+ if (ret) {
+ goto end;
+ }
+ }
+
+ /* Close events element */
+ ret = mi_lttng_writer_close_element(writer);
+
+end:
+ return ret;
+}
+
+/*
+ * List agent events for a specific session using the handle.
+ *
+ * Return CMD_SUCCESS on success else a negative value.
+ */
+static int list_session_agent_events(void)
+{
+ int ret = CMD_SUCCESS, count, i;
+ struct lttng_event *events = NULL;
+
+ count = lttng_list_events(handle, "", &events);