From: Mathieu Desnoyers Date: Tue, 16 Jul 2013 01:06:07 +0000 (-0400) Subject: Fix: add missing metadata socket lock X-Git-Tag: v2.3.0-rc1~18 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=75d83e506938a3e673ad19bb11838ee88e977e72;p=lttng-tools.git Fix: add missing metadata socket lock Protect metadata socket, which can be accessed concurrently by the metadata timer and by snapshot. Reviewed-by: Julien Desfossez Signed-off-by: Mathieu Desnoyers --- diff --git a/src/common/consumer.c b/src/common/consumer.c index a26a41554..6e99a7f52 100644 --- a/src/common/consumer.c +++ b/src/common/consumer.c @@ -1153,6 +1153,7 @@ struct lttng_consumer_local_data *lttng_consumer_create( ctx->consumer_error_socket = -1; ctx->consumer_metadata_socket = -1; + pthread_mutex_init(&ctx->metadata_socket_lock, NULL); /* assign the callbacks */ ctx->on_buffer_ready = buffer_ready; ctx->on_recv_channel = recv_channel; diff --git a/src/common/consumer.h b/src/common/consumer.h index fe396c017..5a1195008 100644 --- a/src/common/consumer.h +++ b/src/common/consumer.h @@ -396,8 +396,10 @@ struct lttng_consumer_local_data { enum lttng_consumer_type type; /* socket to communicate errors with sessiond */ int consumer_error_socket; - /* socket to ask metadata to sessiond */ + /* socket to ask metadata to sessiond. */ int consumer_metadata_socket; + /* Protect consumer_metadata_socket. */ + pthread_mutex_t metadata_socket_lock; /* socket to exchange commands with sessiond */ char *consumer_command_sock_path; /* communication with splice */ diff --git a/src/common/ust-consumer/ust-consumer.c b/src/common/ust-consumer/ust-consumer.c index 6b47ec0c9..986826fca 100644 --- a/src/common/ust-consumer/ust-consumer.c +++ b/src/common/ust-consumer/ust-consumer.c @@ -1890,6 +1890,7 @@ int lttng_ustconsumer_request_metadata(struct lttng_consumer_local_data *ctx, channel->session_id, channel->session_id_per_pid); + pthread_mutex_lock(&ctx->metadata_socket_lock); ret = lttcomm_send_unix_sock(ctx->consumer_metadata_socket, &request, sizeof(request)); if (ret < 0) { @@ -1955,5 +1956,6 @@ int lttng_ustconsumer_request_metadata(struct lttng_consumer_local_data *ctx, ret = 0; end: + pthread_mutex_unlock(&ctx->metadata_socket_lock); return ret; }