From: Jérémie Galarneau Date: Thu, 3 May 2018 18:35:24 +0000 (-0400) Subject: Enforce locking assumptions during channel creation X-Git-Tag: v2.11.0-rc1~248 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=71e0a100af7369c2a56db35af7b864eeb5ca4f48;p=lttng-tools.git Enforce locking assumptions during channel creation Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/session.c b/src/bin/lttng-sessiond/session.c index 01cdfdc00..16431ca15 100644 --- a/src/bin/lttng-sessiond/session.c +++ b/src/bin/lttng-sessiond/session.c @@ -134,6 +134,14 @@ void session_lock_list(void) pthread_mutex_lock(<t_session_list.lock); } +/* + * Try to acquire session list lock + */ +int session_trylock_list(void) +{ + return pthread_mutex_trylock(<t_session_list.lock); +} + /* * Release session list lock */ diff --git a/src/bin/lttng-sessiond/session.h b/src/bin/lttng-sessiond/session.h index 3ace323ba..92e7a11ad 100644 --- a/src/bin/lttng-sessiond/session.h +++ b/src/bin/lttng-sessiond/session.h @@ -212,6 +212,7 @@ int session_destroy(struct ltt_session *session); void session_lock(struct ltt_session *session); void session_lock_list(void); +int session_trylock_list(void); void session_unlock(struct ltt_session *session); void session_unlock_list(void); diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c index 8120b6df2..62971067c 100644 --- a/src/bin/lttng-sessiond/ust-app.c +++ b/src/bin/lttng-sessiond/ust-app.c @@ -2847,6 +2847,7 @@ error: * Create and send to the application the created buffers with per UID buffers. * * This MUST be called with a RCU read side lock acquired. + * The session list lock and the session's lock must be acquired. * * Return 0 on success else a negative value. */ @@ -2939,6 +2940,8 @@ static int create_channel_per_uid(struct ust_app *app, session = session_find_by_id(ua_sess->tracing_id); assert(session); + assert(pthread_mutex_trylock(&session->lock)); + assert(session_trylock_list()); cmd_ret = notification_thread_command_add_channel( notification_thread_handle, session->name, ua_sess->euid, ua_sess->egid, @@ -2970,6 +2973,7 @@ error: * Create and send to the application the created buffers with per PID buffers. * * Called with UST app session lock held. + * The session list lock and the session's lock must be acquired. * * Return 0 on success else a negative value. */ @@ -3032,6 +3036,9 @@ static int create_channel_per_pid(struct ust_app *app, chan_reg->consumer_key = ua_chan->key; pthread_mutex_unlock(®istry->lock); + assert(pthread_mutex_trylock(&session->lock)); + assert(session_trylock_list()); + cmd_ret = notification_thread_command_add_channel( notification_thread_handle, session->name, ua_sess->euid, ua_sess->egid,