From: David Goulet Date: Mon, 26 Aug 2013 17:28:04 +0000 (-0400) Subject: Lock consumer data before fd check during destroy X-Git-Tag: v2.3.0-rc3~22 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=fdadac0853f699c7dc829162955cc8f459b6d2f2;p=lttng-tools.git Lock consumer data before fd check during destroy Also, a consumer state error is added just before update UST applications on registration. Fixes #595 Acked-by: Mathieu Desnoyers Signed-off-by: David Goulet --- diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index b688a4c09..6c6386d2b 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -727,6 +727,12 @@ static void update_ust_app(int app_sock) { struct ltt_session *sess, *stmp; + /* Consumer is in an ERROR state. Stop any application update. */ + if (uatomic_read(&ust_consumerd_state) == CONSUMER_ERROR) { + /* Stop the update process since the consumer is dead. */ + return; + } + /* For all tracing session(s) */ cds_list_for_each_entry_safe(sess, stmp, &session_list_ptr->head, list) { session_lock(sess); @@ -1135,6 +1141,13 @@ restart_poll: exit: error: + /* + * We lock here because we are about to close the sockets and some other + * thread might be using them so wait before we are exclusive which will + * abort all other consumer command by other threads. + */ + pthread_mutex_lock(&consumer_data->lock); + /* Immediately set the consumerd state to stopped */ if (consumer_data->type == LTTNG_CONSUMER_KERNEL) { uatomic_set(&kernel_consumerd_state, CONSUMER_ERROR); @@ -1166,9 +1179,6 @@ error: PERROR("close"); } } - /* Cleanup metadata socket mutex. */ - pthread_mutex_destroy(consumer_data->metadata_sock.lock); - free(consumer_data->metadata_sock.lock); if (sock >= 0) { ret = close(sock); @@ -1180,6 +1190,10 @@ error: unlink(consumer_data->err_unix_sock_path); unlink(consumer_data->cmd_unix_sock_path); consumer_data->pid = 0; + pthread_mutex_unlock(&consumer_data->lock); + /* Cleanup metadata socket mutex. */ + pthread_mutex_destroy(consumer_data->metadata_sock.lock); + free(consumer_data->metadata_sock.lock); lttng_poll_clean(&events); error_poll: