+ leftover = poptGetArg(pc);
+ if (leftover) {
+ ERR("Unknown argument: %s", leftover);
+ ret = CMD_ERROR;
+ goto end;
+ }
+
+ /* Mi check */
+ if (lttng_opt_mi) {
+ the_writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi);
+ if (!the_writer) {
+ ret = CMD_ERROR;
+ goto end;
+ }
+
+ /* Open command element */
+ ret = mi_lttng_writer_command_open(the_writer,
+ mi_lttng_element_command_load);
+ if (ret) {
+ ret = CMD_ERROR;
+ goto end;
+ }
+
+ /* Open output element */
+ ret = mi_lttng_writer_open_element(the_writer,
+ mi_lttng_element_command_output);
+ if (ret) {
+ ret = CMD_ERROR;
+ goto end;
+ }
+ }
+
+ /* Prepare load attributes */
+ session_attr = lttng_load_session_attr_create();
+ if (!session_attr) {
+ ERR("Failed to create load session attributes");
+ ret = CMD_ERROR;
+ goto end;
+ }
+
+ /*
+ * Set the input url
+ * lttng_load_session_attr_set_input_url only suppports absolute path.
+ * Use realpath to resolve any relative path.
+ * */
+ if (the_opt_input_path) {
+ input_path = realpath(the_opt_input_path, NULL);
+ if (!input_path) {
+ PERROR("Invalid input path");
+ ret = CMD_ERROR;
+ goto end;
+ }
+ } else {
+ input_path = NULL;
+ }
+
+ ret = lttng_load_session_attr_set_input_url(session_attr,
+ input_path);
+ if (ret) {
+ ERR("Invalid input path");
+ ret = CMD_ERROR;
+ goto end;
+ }
+
+ /* Set the session name. NULL means all sessions should be loaded */
+ ret = lttng_load_session_attr_set_session_name(session_attr,
+ the_session_name);
+ if (ret) {
+ ERR("Invalid session name");
+ ret = CMD_ERROR;
+ goto end;
+ }
+
+ /* Set the overwrite attribute */
+ ret = lttng_load_session_attr_set_overwrite(session_attr, the_opt_force);
+ if (ret) {
+ ERR("Force argument could not be applied");
+ ret = CMD_ERROR;
+ goto end;
+ }
+
+ /* Set the overrides attributes if any */
+ if (the_opt_override_url) {
+ ret = lttng_load_session_attr_set_override_url(session_attr,
+ the_opt_override_url);
+ if (ret) {
+ ERR("Url override is invalid");
+ goto end;
+ }
+ }
+
+ if (the_opt_override_session_name) {
+ if (the_opt_load_all) {
+ ERR("Options --all and --override-name cannot be used simultaneously");
+ ret = CMD_ERROR;
+ goto end;
+ }
+ ret = lttng_load_session_attr_set_override_session_name(session_attr,
+ the_opt_override_session_name);
+ if (ret) {
+ ERR("Failed to set session name override");
+ ret = CMD_ERROR;
+ goto end;
+ }
+ }
+
+ ret = lttng_load_session(session_attr);