From 5feafd413038626a47de89c0b29e41673b68818a Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 21 Dec 2016 17:56:24 -0500 Subject: [PATCH] Fix: protect the channel's metadata stream using the metadata cache lock MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The consumer_thread_data_poll and consumer_thread_metadata_poll both access the channel's metadata stream. During a session destruction, consumer_thread_metadata_poll will destroy all metadata streams. However, the consumer_thread_data_poll may still invoke a consumer_metadata_cache_write() triggered by a "ready" subbuffer. Hence, the metadata stream must be protected from this action by the metadata cache lock. Signed-off-by: Jérémie Galarneau --- src/common/consumer/consumer-metadata-cache.c | 2 +- src/common/consumer/consumer.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/common/consumer/consumer-metadata-cache.c b/src/common/consumer/consumer-metadata-cache.c index 3211ec1e8..6b15375e1 100644 --- a/src/common/consumer/consumer-metadata-cache.c +++ b/src/common/consumer/consumer-metadata-cache.c @@ -147,7 +147,7 @@ int consumer_metadata_cache_write(struct lttng_consumer_channel *channel, char dummy = 'c'; cache->max_offset = offset + len; - if (channel->monitor) { + if (channel->monitor && channel->metadata_stream) { size_ret = lttng_write(channel->metadata_stream->ust_metadata_poll_pipe[1], &dummy, 1); if (size_ret < 1) { diff --git a/src/common/consumer/consumer.c b/src/common/consumer/consumer.c index 929be6553..54a0531d5 100644 --- a/src/common/consumer/consumer.c +++ b/src/common/consumer/consumer.c @@ -47,6 +47,7 @@ #include #include #include +#include struct lttng_consumer_global_data consumer_data = { .stream_count = 0, @@ -2051,6 +2052,7 @@ void consumer_del_metadata_stream(struct lttng_consumer_stream *stream, pthread_mutex_lock(&consumer_data.lock); pthread_mutex_lock(&stream->chan->lock); + pthread_mutex_lock(&stream->chan->metadata_cache->lock); pthread_mutex_lock(&stream->lock); /* Remove any reference to that stream. */ @@ -2076,6 +2078,7 @@ void consumer_del_metadata_stream(struct lttng_consumer_stream *stream, stream->chan->metadata_stream = NULL; pthread_mutex_unlock(&stream->lock); + pthread_mutex_unlock(&stream->chan->metadata_cache->lock); pthread_mutex_unlock(&stream->chan->lock); pthread_mutex_unlock(&consumer_data.lock); -- 2.39.5