+ /* Mi check */
+ if (lttng_opt_mi) {
+ writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi);
+ if (!writer) {
+ ret = -LTTNG_ERR_NOMEM;
+ goto end_destroy;
+ }
+
+ /* Open command element */
+ ret = mi_lttng_writer_command_open(writer,
+ mi_lttng_element_command_save);
+ if (ret) {
+ ret = CMD_ERROR;
+ goto end_destroy;
+ }
+
+ /* Open output element */
+ ret = mi_lttng_writer_open_element(writer,
+ mi_lttng_element_command_output);
+ if (ret) {
+ ret = CMD_ERROR;
+ goto end_destroy;
+ }
+ }
+
+ command_ret = lttng_save_session(attr);
+ if (command_ret < 0) {
+ ERR("%s", lttng_strerror(command_ret));
+ success = 0;
+ } else {
+ /* Inform the user of what just happened on success. */
+ if (session_name && opt_output_path) {
+ MSG("Session %s saved successfully in %s.", session_name,
+ opt_output_path);
+ } else if (session_name && !opt_output_path) {
+ MSG("Session %s saved successfully.", session_name);
+ } else if (!session_name && opt_output_path) {
+ MSG("All sessions have been saved successfully in %s.",
+ opt_output_path);
+ } else {
+ MSG("All sessions have been saved successfully.");
+ }
+ success = 1;
+ }
+
+ /* Mi Printing and closing */
+ if (lttng_opt_mi) {
+ /* Mi print */
+ ret = mi_save_print(session_name);
+ if (ret) {
+ ret = CMD_ERROR;
+ goto end_destroy;
+ }
+
+ /* Close output element */
+ ret = mi_lttng_writer_close_element(writer);
+ if (ret) {
+ ret = CMD_ERROR;
+ goto end_destroy;
+ }
+
+ /* Success ? */
+ ret = mi_lttng_writer_write_element_bool(writer,
+ mi_lttng_element_command_success, success);
+ if (ret) {
+ ret = CMD_ERROR;
+ goto end_destroy;
+ }
+
+ /* Command element close */
+ ret = mi_lttng_writer_command_close(writer);
+ if (ret) {
+ ret = CMD_ERROR;
+ goto end_destroy;