+
+ /* Open command element */
+ ret = mi_lttng_writer_command_open(writer,
+ mi_lttng_element_command_destroy);
+ if (ret) {
+ ret = CMD_ERROR;
+ goto end;
+ }
+
+ /* Open output element */
+ ret = mi_lttng_writer_open_element(writer,
+ mi_lttng_element_command_output);
+ if (ret) {
+ ret = CMD_ERROR;
+ goto end;
+ }
+
+ /* For validation and semantic purpose we open a sessions element */
+ ret = mi_lttng_sessions_open(writer);
+ if (ret) {
+ ret = CMD_ERROR;
+ goto end;
+ }
+ }
+
+ /* Recuperate all sessions for further operation */
+ count = lttng_list_sessions(&sessions);
+ if (count < 0) {
+ ERR("%s", lttng_strerror(count));
+ command_ret = CMD_ERROR;
+ success = 0;
+ goto mi_closing;
+ }
+
+ /* Ignore session name in case all sessions are to be destroyed */
+ if (opt_destroy_all) {
+ command_ret = destroy_all_sessions(sessions, count);
+ if (command_ret) {
+ success = 0;
+ }
+ } else {
+ opt_session_name = (char *) poptGetArg(pc);
+
+ 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;
+ ERR("%s during the destruction of session \"%s\"",
+ lttng_strerror(command_ret),
+ sessions[i].name);
+ }
+ }
+ }
+
+ if (!found) {
+ ERR("Session name %s not found", session_name);
+ command_ret = LTTNG_ERR_SESS_NOT_FOUND;
+ success = 0;
+ goto mi_closing;
+ }