+ if (path) {
+ td = fmt->open_trace(path, O_RDONLY, packet_seek, NULL);
+ if (!td) {
+ fprintf(stderr, "[warning] [Context] Cannot open_trace of the format %s .\n\n",
+ path);
+ ret = -1;
+ goto end;
+ }
+ } else {
+ td = fmt->open_mmap_trace(stream_list, packet_seek, metadata);
+ if (!td) {
+ fprintf(stderr, "[error] [Context] Cannot open_trace of the format %s .\n\n",
+ path);
+ ret = -1;
+ goto end;
+ }
+ }
+
+ /* Create an handle for the trace */
+ handle = bt_trace_handle_create(ctx);
+ if (handle < 0) {
+ fprintf(stderr, "[error] [Context] Creating trace handle %s .\n\n",
+ path);
+ ret = -1;
+ goto end;
+ }
+ handle->format = fmt;
+ handle->td = td;
+ if (path) {
+ strncpy(handle->path, path, PATH_MAX);
+ handle->path[PATH_MAX - 1] = '\0';
+ }
+
+ if (fmt->set_handle)
+ fmt->set_handle(td, handle);
+ if (fmt->set_context)
+ fmt->set_context(td, ctx);
+
+ /* Add new handle to container */
+ g_hash_table_insert(ctx->trace_handles,
+ (gpointer) (unsigned long) handle->id,
+ handle);
+ ret = trace_collection_add(ctx->tc, td);
+ if (ret != 0)
+ goto end;
+
+ ret = fmt->convert_index_timestamp(td);
+ if (ret < 0)
+ goto end;