From: Mathieu Desnoyers Date: Thu, 3 Nov 2011 23:33:24 +0000 (-0400) Subject: ust consumer: flag shm/wait fd as copy X-Git-Tag: v2.0-pre15~159 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=b5c5fc2947ec79834e054e0117414b717faeee4d;p=lttng-tools.git ust consumer: flag shm/wait fd as copy Signed-off-by: Mathieu Desnoyers --- 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; }