- /*
- * This is to avoid a race between the initialization of this object and
- * the close of the given stream. If the stream is unable to find this
- * viewer stream when closing, this copy will at least take the latest
- * value. We also need that for the seek_last.
- */
- vstream->total_index_received = stream->total_index_received;
+ switch (seek_t) {
+ case LTTNG_VIEWER_SEEK_BEGINNING:
+ {
+ uint64_t seq_tail = tracefile_array_get_seq_tail(stream->tfa);
+
+ if (seq_tail == -1ULL) {
+ /*
+ * Tail may not be initialized yet. Nonetheless, we know
+ * we want to send the first index once it becomes
+ * available.
+ */
+ seq_tail = 0;
+ }
+ vstream->current_tracefile_id =
+ tracefile_array_get_file_index_tail(stream->tfa);
+ vstream->index_sent_seqcount = seq_tail;
+ break;
+ }
+ case LTTNG_VIEWER_SEEK_LAST:
+ vstream->current_tracefile_id =
+ tracefile_array_get_file_index_head(stream->tfa);
+ /*
+ * We seek at the very end of each stream, awaiting for
+ * a future packet to eventually come in.
+ *
+ * We don't need to check the head position for -1ULL since the
+ * increment will set it to 0.
+ */
+ vstream->index_sent_seqcount =
+ tracefile_array_get_seq_head(stream->tfa) + 1;
+ break;
+ default:
+ goto error_unlock;
+ }