+ int ret = 0, trace_ids = 0;
+
+ if ((strncmp(path, NET4_URL_PREFIX, sizeof(NET4_URL_PREFIX) - 1)) == 0 ||
+ (strncmp(path, NET6_URL_PREFIX, sizeof(NET6_URL_PREFIX) - 1)) == 0 ||
+ (strncmp(path, NET_URL_PREFIX, sizeof(NET_URL_PREFIX) - 1)) == 0) {
+ ret = bt_context_add_trace(ctx,
+ path, format_str, packet_seek, NULL, NULL);
+ if (ret < 0) {
+ fprintf(stderr, "[warning] [Context] cannot open trace \"%s\" "
+ "for reading.\n", path);
+ }
+ return ret;
+ }
+ /* Should lock traversed_paths mutex here if used in multithread */
+
+ traversed_paths = g_ptr_array_new();
+ ret = nftw(path, traverse_trace_dir, 10, 0);
+
+ /* Process the array if ntfw did not return a fatal error */
+ if (ret >= 0) {
+ int i;
+
+ for (i = 0; i < traversed_paths->len; i++) {
+ GString *trace_path = g_ptr_array_index(traversed_paths,
+ i);
+ int trace_id = bt_context_add_trace(ctx,
+ trace_path->str,
+ format_str,
+ packet_seek,
+ NULL,
+ NULL);
+ if (trace_id < 0) {
+ fprintf(stderr, "[warning] [Context] cannot open trace \"%s\" from %s "
+ "for reading.\n", trace_path->str, path);
+ /* Allow to skip erroneous traces. */
+ ret = 1; /* partial error */
+ } else {
+ trace_ids++;
+ }
+ g_string_free(trace_path, TRUE);
+ }
+ }
+
+ g_ptr_array_free(traversed_paths, TRUE);
+ traversed_paths = NULL;
+
+ /* Should unlock traversed paths mutex here if used in multithread */
+
+ /*
+ * Return an error if no trace can be opened.
+ */
+ if (trace_ids == 0) {
+ fprintf(stderr, "[error] Cannot open any trace for reading.\n\n");
+ ret = -ENOENT; /* failure */
+ }
+ return ret;
+}
+
+static
+int trace_pre_handler(struct bt_trace_descriptor *td_write,
+ struct bt_context *ctx)
+{
+ struct ctf_text_stream_pos *sout;
+ struct trace_collection *tc;
+ int ret, i;
+
+ sout = container_of(td_write, struct ctf_text_stream_pos,
+ trace_descriptor);
+
+ if (!sout->parent.pre_trace_cb)
+ return 0;