From b5c5fc2947ec79834e054e0117414b717faeee4d Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Thu, 3 Nov 2011 19:33:24 -0400 Subject: [PATCH 1/1] ust consumer: flag shm/wait fd as copy Signed-off-by: Mathieu Desnoyers --- include/lttng/lttng-consumer.h | 4 ++++ liblttng-consumer/lttng-consumer.c | 10 ++++++---- liblttng-ustconsumer/lttng-ustconsumer.c | 15 +++++++-------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/include/lttng/lttng-consumer.h b/include/lttng/lttng-consumer.h index a0277cf04..7751570ef 100644 --- a/include/lttng/lttng-consumer.h +++ b/include/lttng/lttng-consumer.h @@ -83,6 +83,8 @@ struct lttng_consumer_channel { size_t mmap_len; struct lttng_ust_shm_handle *handle; int nr_streams; + int shm_fd_is_copy; + int wait_fd_is_copy; }; /* Forward declaration for UST. */ @@ -110,6 +112,8 @@ struct lttng_consumer_stream { void *mmap_base; size_t mmap_len; enum lttng_event_output output; /* splice or mmap */ + int shm_fd_is_copy; + int wait_fd_is_copy; /* For UST */ struct lttng_ust_lib_ring_buffer *buf; int cpu; diff --git a/liblttng-consumer/lttng-consumer.c b/liblttng-consumer/lttng-consumer.c index 081d6142b..5311860e0 100644 --- a/liblttng-consumer/lttng-consumer.c +++ b/liblttng-consumer/lttng-consumer.c @@ -125,10 +125,11 @@ void consumer_del_stream(struct lttng_consumer_stream *stream) if (stream->out_fd >= 0) { close(stream->out_fd); } - if (stream->wait_fd >= 0) { + if (stream->wait_fd >= 0 && !stream->wait_fd_is_copy) { close(stream->wait_fd); } - if (stream->shm_fd >= 0 && stream->wait_fd != stream->shm_fd) { + if (stream->shm_fd >= 0 && stream->wait_fd != stream->shm_fd + && !stream->shm_fd_is_copy) { close(stream->shm_fd); } if (!--stream->chan->refcount) @@ -282,10 +283,11 @@ void consumer_del_channel(struct lttng_consumer_channel *channel) perror("munmap"); } } - if (channel->wait_fd >= 0) { + if (channel->wait_fd >= 0 && !channel->wait_fd_is_copy) { close(channel->wait_fd); } - if (channel->shm_fd >= 0 && channel->wait_fd != channel->shm_fd) { + if (channel->shm_fd >= 0 && channel->wait_fd != channel->shm_fd + && !channel->shm_fd_is_copy) { close(channel->shm_fd); } free(channel); diff --git a/liblttng-ustconsumer/lttng-ustconsumer.c b/liblttng-ustconsumer/lttng-ustconsumer.c index bf3ae0845..db0ba05bd 100644 --- a/liblttng-ustconsumer/lttng-ustconsumer.c +++ b/liblttng-ustconsumer/lttng-ustconsumer.c @@ -272,11 +272,11 @@ int lttng_ustconsumer_allocate_channel(struct lttng_consumer_channel *chan) return -ENOMEM; } /* - * The channel shm and wait fds are passed to ustctl, set them - * to -1 here. + * The channel fds are passed to ustctl, we only keep a copy. */ - chan->shm_fd = -1; - chan->wait_fd = -1; + chan->shm_fd_is_copy = 1; + chan->wait_fd_is_copy = 1; + return 0; } @@ -305,11 +305,10 @@ int lttng_ustconsumer_allocate_stream(struct lttng_consumer_stream *stream) return -EINVAL; } /* - * The stream shm and wait fds are passed to ustctl, set them to - * -1 here. + * The stream fds are passed to ustctl, we only keep a copy. */ - stream->shm_fd = -1; - stream->wait_fd = -1; + stream->shm_fd_is_copy = 1; + stream->wait_fd_is_copy = 1; return 0; } -- 2.34.1