+ if (!opt_session_name) {
+ /* No session name specified, lookup default */
+ session_name = get_session_name();
+ if (session_name == NULL) {
+ command_ret = CMD_ERROR;
+ success = 0;
+ goto mi_closing;
+ }
+ } else {
+ session_name = opt_session_name;
+ }
+
+ /* Find the corresponding lttng_session struct */
+ found = 0;
+ for (i = 0; i < count; i++) {
+ if (strncmp(sessions[i].name, session_name, NAME_MAX) == 0) {
+ found = 1;
+ command_ret = destroy_session(&sessions[i]);
+ if (command_ret) {
+ success = 0;
+ }
+
+ }
+ }
+
+ if (!found) {
+ ERR("Session name %s not found", session_name);
+ command_ret = LTTNG_ERR_SESS_NOT_FOUND;
+ success = 0;
+ goto mi_closing;
+ }
+ }
+
+mi_closing:
+ /* Mi closing */
+ if (lttng_opt_mi) {
+ /* Close sessions and output element element */
+ ret = mi_lttng_close_multi_element(writer, 2);
+ if (ret) {
+ ret = CMD_ERROR;
+ goto end;
+ }
+
+ /* Success ? */
+ ret = mi_lttng_writer_write_element_bool(writer,
+ mi_lttng_element_command_success, success);
+ if (ret) {
+ ret = CMD_ERROR;
+ goto end;
+ }
+
+ /* Command element close */
+ ret = mi_lttng_writer_command_close(writer);
+ if (ret) {
+ ret = CMD_ERROR;
+ goto end;
+ }
+ }