We should at least output one packet before a stream can be considered
as readable. So far, for PID buffers, if an application exits at the
wrong timing before a stop waiting for data pending, empty streams could
be visible by a babeltrace executed after data pending incorrectly
returned false.
Fix it by considering a stream for which the consumerd has written 0
bytes to the output as having data pending.
This applies to 2.3-rc and stable-2.2.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
stream->key = stream_key;
stream->out_fd = -1;
stream->out_fd_offset = 0;
stream->key = stream_key;
stream->out_fd = -1;
stream->out_fd_offset = 0;
+ stream->output_written = 0;
stream->state = state;
stream->uid = uid;
stream->gid = gid;
stream->state = state;
stream->uid = uid;
stream->gid = gid;
SYNC_FILE_RANGE_WRITE);
stream->out_fd_offset += ret;
}
SYNC_FILE_RANGE_WRITE);
stream->out_fd_offset += ret;
}
+ stream->output_written += ret;
written += ret;
}
lttng_consumer_sync_trace_file(stream, orig_offset);
written += ret;
}
lttng_consumer_sync_trace_file(stream, orig_offset);
SYNC_FILE_RANGE_WRITE);
stream->out_fd_offset += ret_splice;
}
SYNC_FILE_RANGE_WRITE);
stream->out_fd_offset += ret_splice;
}
+ stream->output_written += ret_splice;
written += ret_splice;
}
lttng_consumer_sync_trace_file(stream, orig_offset);
written += ret_splice;
}
lttng_consumer_sync_trace_file(stream, orig_offset);
*/
ret = cds_lfht_is_node_deleted(&stream->node.node);
if (!ret) {
*/
ret = cds_lfht_is_node_deleted(&stream->node.node);
if (!ret) {
+ /*
+ * An empty output file is not valid. We need at least one packet
+ * generated per stream, even if it contains no event, so it
+ * contains at least one packet header.
+ */
+ if (stream->output_written == 0) {
+ pthread_mutex_unlock(&stream->lock);
+ goto data_pending;
+ }
/* Check the stream if there is data in the buffers. */
ret = data_pending(stream);
if (ret == 1) {
/* Check the stream if there is data in the buffers. */
ret = data_pending(stream);
if (ret == 1) {
int out_fd; /* output file to write the data */
/* Write position in the output file descriptor */
off_t out_fd_offset;
int out_fd; /* output file to write the data */
/* Write position in the output file descriptor */
off_t out_fd_offset;
+ /* Amount of bytes written to the output */
+ uint64_t output_written;
enum lttng_consumer_stream_state state;
int shm_fd_is_copy;
int data_read;
enum lttng_consumer_stream_state state;
int shm_fd_is_copy;
int data_read;