From fb45065e7ccafc636e6eec7ab2a463c49e603ebb Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 24 Aug 2015 22:50:09 -0400 Subject: [PATCH] Fix: ust-app: protect app socket protocol with lock MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Many threads can access the application socket (cmd handling thread and application handling thread) concurrently. Therefore, we need to protect it with a mutex. Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau --- src/bin/lttng-sessiond/buffer-registry.c | 4 +- src/bin/lttng-sessiond/main.c | 2 +- src/bin/lttng-sessiond/ust-app.c | 154 ++++++++++++++++++++--- src/bin/lttng-sessiond/ust-app.h | 10 +- src/bin/lttng-sessiond/ust-consumer.c | 4 + src/bin/lttng-sessiond/ust-ctl.h | 10 +- 6 files changed, 151 insertions(+), 33 deletions(-) diff --git a/src/bin/lttng-sessiond/buffer-registry.c b/src/bin/lttng-sessiond/buffer-registry.c index b4667a41b..10758f9b8 100644 --- a/src/bin/lttng-sessiond/buffer-registry.c +++ b/src/bin/lttng-sessiond/buffer-registry.c @@ -467,7 +467,7 @@ void buffer_reg_stream_destroy(struct buffer_reg_stream *regp, { int ret; - ret = ust_ctl_release_object(-1, regp->obj.ust); + ret = ust_app_release_object(NULL, regp->obj.ust); if (ret < 0 && ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) { ERR("Buffer reg stream release obj handle %d failed with ret %d", regp->obj.ust->handle, ret); @@ -527,7 +527,7 @@ void buffer_reg_channel_destroy(struct buffer_reg_channel *regp, } if (regp->obj.ust) { - ret = ust_ctl_release_object(-1, regp->obj.ust); + ret = ust_app_release_object(NULL, regp->obj.ust); if (ret < 0 && ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) { ERR("Buffer reg channel release obj handle %d failed with ret %d", regp->obj.ust->handle, ret); diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index 43f750a82..b5cfe307d 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -1989,7 +1989,7 @@ static void *thread_dispatch_ust_registration(void *data) * Don't care about return value. Let the manage apps threads * handle app unregistration upon socket close. */ - (void) ust_app_register_done(app->sock); + (void) ust_app_register_done(app); /* * Even if the application socket has been closed, send the app diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c index fc4b7085e..c4d9fb5a4 100644 --- a/src/bin/lttng-sessiond/ust-app.c +++ b/src/bin/lttng-sessiond/ust-app.c @@ -262,14 +262,17 @@ error: * this function. */ static -void delete_ust_app_ctx(int sock, struct ust_app_ctx *ua_ctx) +void delete_ust_app_ctx(int sock, struct ust_app_ctx *ua_ctx, + struct ust_app *app) { int ret; assert(ua_ctx); if (ua_ctx->obj) { + pthread_mutex_lock(&app->sock_lock); ret = ustctl_release_object(sock, ua_ctx->obj); + pthread_mutex_unlock(&app->sock_lock); if (ret < 0 && ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) { ERR("UST app sock %d release ctx obj handle %d failed with ret %d", sock, ua_ctx->obj->handle, ret); @@ -284,7 +287,8 @@ void delete_ust_app_ctx(int sock, struct ust_app_ctx *ua_ctx) * this function. */ static -void delete_ust_app_event(int sock, struct ust_app_event *ua_event) +void delete_ust_app_event(int sock, struct ust_app_event *ua_event, + struct ust_app *app) { int ret; @@ -294,7 +298,9 @@ void delete_ust_app_event(int sock, struct ust_app_event *ua_event) if (ua_event->exclusion != NULL) free(ua_event->exclusion); if (ua_event->obj != NULL) { + pthread_mutex_lock(&app->sock_lock); ret = ustctl_release_object(sock, ua_event->obj); + pthread_mutex_unlock(&app->sock_lock); if (ret < 0 && ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) { ERR("UST app sock %d release event obj failed with ret %d", sock, ret); @@ -309,14 +315,17 @@ void delete_ust_app_event(int sock, struct ust_app_event *ua_event) * * Return 0 on success or else a negative value. */ -static int release_ust_app_stream(int sock, struct ust_app_stream *stream) +static int release_ust_app_stream(int sock, struct ust_app_stream *stream, + struct ust_app *app) { int ret = 0; assert(stream); if (stream->obj) { + pthread_mutex_lock(&app->sock_lock); ret = ustctl_release_object(sock, stream->obj); + pthread_mutex_unlock(&app->sock_lock); if (ret < 0 && ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) { ERR("UST app sock %d release stream obj failed with ret %d", sock, ret); @@ -333,11 +342,12 @@ static int release_ust_app_stream(int sock, struct ust_app_stream *stream) * this function. */ static -void delete_ust_app_stream(int sock, struct ust_app_stream *stream) +void delete_ust_app_stream(int sock, struct ust_app_stream *stream, + struct ust_app *app) { assert(stream); - (void) release_ust_app_stream(sock, stream); + (void) release_ust_app_stream(sock, stream, app); free(stream); } @@ -380,7 +390,7 @@ void delete_ust_app_channel(int sock, struct ust_app_channel *ua_chan, /* Wipe stream */ cds_list_for_each_entry_safe(stream, stmp, &ua_chan->streams.head, list) { cds_list_del(&stream->list); - delete_ust_app_stream(sock, stream); + delete_ust_app_stream(sock, stream, app); } /* Wipe context */ @@ -388,7 +398,7 @@ void delete_ust_app_channel(int sock, struct ust_app_channel *ua_chan, cds_list_del(&ua_ctx->list); ret = lttng_ht_del(ua_chan->ctx, &iter); assert(!ret); - delete_ust_app_ctx(sock, ua_ctx); + delete_ust_app_ctx(sock, ua_ctx, app); } /* Wipe events */ @@ -396,7 +406,7 @@ void delete_ust_app_channel(int sock, struct ust_app_channel *ua_chan, node.node) { ret = lttng_ht_del(ua_chan->events, &iter); assert(!ret); - delete_ust_app_event(sock, ua_event); + delete_ust_app_event(sock, ua_event, app); } if (ua_chan->session->buffer_type == LTTNG_BUFFER_PER_PID) { @@ -412,7 +422,9 @@ void delete_ust_app_channel(int sock, struct ust_app_channel *ua_chan, iter.iter.node = &ua_chan->ust_objd_node.node; ret = lttng_ht_del(app->ust_objd, &iter); assert(!ret); + pthread_mutex_lock(&app->sock_lock); ret = ustctl_release_object(sock, ua_chan->obj); + pthread_mutex_unlock(&app->sock_lock); if (ret < 0 && ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) { ERR("UST app sock %d release channel obj failed with ret %d", sock, ret); @@ -423,6 +435,33 @@ void delete_ust_app_channel(int sock, struct ust_app_channel *ua_chan, call_rcu(&ua_chan->rcu_head, delete_ust_app_channel_rcu); } +int ust_app_register_done(struct ust_app *app) +{ + int ret; + + pthread_mutex_lock(&app->sock_lock); + ret = ustctl_register_done(app->sock); + pthread_mutex_unlock(&app->sock_lock); + return ret; +} + +int ust_app_release_object(struct ust_app *app, struct lttng_ust_object_data *data) +{ + int ret, sock; + + if (app) { + pthread_mutex_lock(&app->sock_lock); + sock = app->sock; + } else { + sock = -1; + } + ret = ustctl_release_object(sock, data); + if (app) { + pthread_mutex_unlock(&app->sock_lock); + } + return ret; +} + /* * Push metadata to consumer socket. * @@ -743,7 +782,9 @@ void delete_ust_app_session(int sock, struct ust_app_session *ua_sess, } if (ua_sess->handle != -1) { + pthread_mutex_lock(&app->sock_lock); ret = ustctl_release_handle(sock, ua_sess->handle); + pthread_mutex_unlock(&app->sock_lock); if (ret < 0 && ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) { ERR("UST app sock %d release session handle failed with ret %d", sock, ret); @@ -1153,8 +1194,10 @@ int create_ust_channel_context(struct ust_app_channel *ua_chan, health_code_update(); + pthread_mutex_lock(&app->sock_lock); ret = ustctl_add_context(app->sock, &ua_ctx->ctx, ua_chan->obj, &ua_ctx->obj); + pthread_mutex_unlock(&app->sock_lock); if (ret < 0) { if (ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) { ERR("UST app create channel context failed for app (pid: %d) " @@ -1203,8 +1246,10 @@ int set_ust_event_filter(struct ust_app_event *ua_event, ret = -LTTNG_ERR_NOMEM; goto error; } + pthread_mutex_lock(&app->sock_lock); ret = ustctl_set_filter(app->sock, ust_bytecode, ua_event->obj); + pthread_mutex_unlock(&app->sock_lock); if (ret < 0) { if (ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) { ERR("UST app event %s filter failed for app (pid: %d) " @@ -1273,7 +1318,9 @@ int set_ust_event_exclusion(struct ust_app_event *ua_event, ret = -LTTNG_ERR_NOMEM; goto error; } + pthread_mutex_lock(&app->sock_lock); ret = ustctl_set_exclusion(app->sock, ust_exclusion, ua_event->obj); + pthread_mutex_unlock(&app->sock_lock); if (ret < 0) { if (ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) { ERR("UST app event %s exclusions failed for app (pid: %d) " @@ -1308,7 +1355,9 @@ static int disable_ust_event(struct ust_app *app, health_code_update(); + pthread_mutex_lock(&app->sock_lock); ret = ustctl_disable(app->sock, ua_event->obj); + pthread_mutex_unlock(&app->sock_lock); if (ret < 0) { if (ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) { ERR("UST app event %s disable failed for app (pid: %d) " @@ -1344,7 +1393,9 @@ static int disable_ust_channel(struct ust_app *app, health_code_update(); + pthread_mutex_lock(&app->sock_lock); ret = ustctl_disable(app->sock, ua_chan->obj); + pthread_mutex_unlock(&app->sock_lock); if (ret < 0) { if (ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) { ERR("UST app channel %s disable failed for app (pid: %d) " @@ -1380,7 +1431,9 @@ static int enable_ust_channel(struct ust_app *app, health_code_update(); + pthread_mutex_lock(&app->sock_lock); ret = ustctl_enable(app->sock, ua_chan->obj); + pthread_mutex_unlock(&app->sock_lock); if (ret < 0) { if (ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) { ERR("UST app channel %s enable failed for app (pid: %d) " @@ -1418,7 +1471,9 @@ static int enable_ust_event(struct ust_app *app, health_code_update(); + pthread_mutex_lock(&app->sock_lock); ret = ustctl_enable(app->sock, ua_event->obj); + pthread_mutex_unlock(&app->sock_lock); if (ret < 0) { if (ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) { ERR("UST app event %s enable failed for app (pid: %d) " @@ -1486,7 +1541,7 @@ static int send_channel_pid_to_ust(struct ust_app *app, } /* We don't need the stream anymore once sent to the tracer. */ cds_list_del(&stream->list); - delete_ust_app_stream(-1, stream); + delete_ust_app_stream(-1, stream, app); } /* Flag the channel that it is sent to the application. */ ua_chan->is_sent = 1; @@ -1510,8 +1565,10 @@ int create_ust_event(struct ust_app *app, struct ust_app_session *ua_sess, health_code_update(); /* Create UST event on tracer */ + pthread_mutex_lock(&app->sock_lock); ret = ustctl_create_event(app->sock, &ua_event->attr, ua_chan->obj, &ua_event->obj); + pthread_mutex_unlock(&app->sock_lock); if (ret < 0) { if (ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) { ERR("Error ustctl create event %s for app pid: %d with ret %d", @@ -2044,7 +2101,9 @@ static int create_ust_app_session(struct ltt_ust_session *usess, health_code_update(); if (ua_sess->handle == -1) { + pthread_mutex_lock(&app->sock_lock); ret = ustctl_create_session(app->sock); + pthread_mutex_unlock(&app->sock_lock); if (ret < 0) { if (ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) { ERR("Creating session for app pid %d with ret %d", @@ -2470,7 +2529,8 @@ error_fd_get: * Return 0 on success or else a negative value. */ static int setup_buffer_reg_streams(struct buffer_reg_channel *reg_chan, - struct ust_app_channel *ua_chan) + struct ust_app_channel *ua_chan, + struct ust_app *app) { int ret = 0; struct ust_app_stream *stream, *stmp; @@ -2499,7 +2559,7 @@ static int setup_buffer_reg_streams(struct buffer_reg_channel *reg_chan, /* We don't need the streams anymore. */ cds_list_del(&stream->list); - delete_ust_app_stream(-1, stream); + delete_ust_app_stream(-1, stream, app); } error: @@ -2563,7 +2623,8 @@ error_create: * Return 0 on success else a negative value. */ static int setup_buffer_reg_channel(struct buffer_reg_session *reg_sess, - struct ust_app_channel *ua_chan, struct buffer_reg_channel *reg_chan) + struct ust_app_channel *ua_chan, struct buffer_reg_channel *reg_chan, + struct ust_app *app) { int ret; @@ -2575,7 +2636,7 @@ static int setup_buffer_reg_channel(struct buffer_reg_session *reg_sess, DBG2("UST app setup buffer registry channel for %s", ua_chan->name); /* Setup all streams for the registry. */ - ret = setup_buffer_reg_streams(reg_chan, ua_chan); + ret = setup_buffer_reg_streams(reg_chan, ua_chan, app); if (ret < 0) { goto error; } @@ -2638,7 +2699,7 @@ static int send_channel_uid_to_ust(struct buffer_reg_channel *reg_chan, ret = ust_consumer_send_stream_to_ust(app, ua_chan, &stream); if (ret < 0) { - (void) release_ust_app_stream(-1, &stream); + (void) release_ust_app_stream(-1, &stream, app); if (ret == -EPIPE || ret == -LTTNG_UST_ERR_EXITING) { ret = -ENOTCONN; /* Caused by app exiting. */ goto error_stream_unlock; @@ -2652,7 +2713,7 @@ static int send_channel_uid_to_ust(struct buffer_reg_channel *reg_chan, * The return value is not important here. This function will output an * error if needed. */ - (void) release_ust_app_stream(-1, &stream); + (void) release_ust_app_stream(-1, &stream, app); } ua_chan->is_sent = 1; @@ -2726,7 +2787,8 @@ static int create_channel_per_uid(struct ust_app *app, /* * Setup the streams and add it to the session registry. */ - ret = setup_buffer_reg_channel(reg_uid->registry, ua_chan, reg_chan); + ret = setup_buffer_reg_channel(reg_uid->registry, + ua_chan, reg_chan, app); if (ret < 0) { ERR("Error setting up UST channel \"%s\"", ua_chan->name); @@ -2972,7 +3034,7 @@ end: error: /* Valid. Calling here is already in a read side lock */ - delete_ust_app_event(-1, ua_event); + delete_ust_app_event(-1, ua_event, app); return ret; } @@ -3163,10 +3225,10 @@ struct ust_app *ust_app_create(struct ust_register_msg *msg, int sock) lta->pid = msg->pid; lttng_ht_node_init_ulong(<a->pid_n, (unsigned long) lta->pid); lta->sock = sock; + pthread_mutex_init(<a->sock_lock, NULL); lttng_ht_node_init_ulong(<a->sock_n, (unsigned long) lta->sock); CDS_INIT_LIST_HEAD(<a->teardown_head); - error: return lta; } @@ -3218,7 +3280,9 @@ int ust_app_version(struct ust_app *app) assert(app); + pthread_mutex_lock(&app->sock_lock); ret = ustctl_tracer_version(app->sock, &app->version); + pthread_mutex_unlock(&app->sock_lock); if (ret < 0) { if (ret != -LTTNG_UST_ERR_EXITING && ret != -EPIPE) { ERR("UST app %d version failed with ret %d", app->sock, ret); @@ -3383,12 +3447,14 @@ int ust_app_list_events(struct lttng_event **events) */ continue; } + pthread_mutex_lock(&app->sock_lock); handle = ustctl_tracepoint_list(app->sock); if (handle < 0) { if (handle != -EPIPE && handle != -LTTNG_UST_ERR_EXITING) { ERR("UST app list events getting handle failed for app pid %d", app->pid); } + pthread_mutex_unlock(&app->sock_lock); continue; } @@ -3396,6 +3462,8 @@ int ust_app_list_events(struct lttng_event **events) &uiter)) != -LTTNG_UST_ERR_NOENT) { /* Handle ustctl error. */ if (ret < 0) { + int release_ret; + if (ret != -LTTNG_UST_ERR_EXITING && ret != -EPIPE) { ERR("UST app tp list get failed for app %d with ret %d", app->sock, ret); @@ -3409,6 +3477,11 @@ int ust_app_list_events(struct lttng_event **events) break; } free(tmp_event); + release_ret = ustctl_release_handle(app->sock, handle); + if (release_ret != -LTTNG_UST_ERR_EXITING && release_ret != -EPIPE) { + ERR("Error releasing app handle for app %d with ret %d", app->sock, release_ret); + } + pthread_mutex_unlock(&app->sock_lock); goto rcu_error; } @@ -3424,9 +3497,16 @@ int ust_app_list_events(struct lttng_event **events) new_tmp_event = realloc(tmp_event, new_nbmem * sizeof(struct lttng_event)); if (new_tmp_event == NULL) { + int release_ret; + PERROR("realloc ust app events"); free(tmp_event); ret = -ENOMEM; + release_ret = ustctl_release_handle(app->sock, handle); + if (release_ret != -LTTNG_UST_ERR_EXITING && release_ret != -EPIPE) { + ERR("Error releasing app handle for app %d with ret %d", app->sock, release_ret); + } + pthread_mutex_unlock(&app->sock_lock); goto rcu_error; } /* Zero the new memory */ @@ -3442,6 +3522,11 @@ int ust_app_list_events(struct lttng_event **events) tmp_event[count].enabled = -1; count++; } + ret = ustctl_release_handle(app->sock, handle); + pthread_mutex_unlock(&app->sock_lock); + if (ret != -LTTNG_UST_ERR_EXITING && ret != -EPIPE) { + ERR("Error releasing app handle for app %d with ret %d", app->sock, ret); + } } ret = count; @@ -3489,12 +3574,14 @@ int ust_app_list_event_fields(struct lttng_event_field **fields) */ continue; } + pthread_mutex_lock(&app->sock_lock); handle = ustctl_tracepoint_field_list(app->sock); if (handle < 0) { if (handle != -EPIPE && handle != -LTTNG_UST_ERR_EXITING) { ERR("UST app list field getting handle failed for app pid %d", app->pid); } + pthread_mutex_unlock(&app->sock_lock); continue; } @@ -3502,6 +3589,8 @@ int ust_app_list_event_fields(struct lttng_event_field **fields) &uiter)) != -LTTNG_UST_ERR_NOENT) { /* Handle ustctl error. */ if (ret < 0) { + int release_ret; + if (ret != -LTTNG_UST_ERR_EXITING && ret != -EPIPE) { ERR("UST app tp list field failed for app %d with ret %d", app->sock, ret); @@ -3515,6 +3604,11 @@ int ust_app_list_event_fields(struct lttng_event_field **fields) break; } free(tmp_event); + release_ret = ustctl_release_handle(app->sock, handle); + pthread_mutex_unlock(&app->sock_lock); + if (release_ret != -LTTNG_UST_ERR_EXITING && release_ret != -EPIPE) { + ERR("Error releasing app handle for app %d with ret %d", app->sock, release_ret); + } goto rcu_error; } @@ -3530,9 +3624,16 @@ int ust_app_list_event_fields(struct lttng_event_field **fields) new_tmp_event = realloc(tmp_event, new_nbmem * sizeof(struct lttng_event_field)); if (new_tmp_event == NULL) { + int release_ret; + PERROR("realloc ust app event fields"); free(tmp_event); ret = -ENOMEM; + release_ret = ustctl_release_handle(app->sock, handle); + pthread_mutex_unlock(&app->sock_lock); + if (release_ret != -LTTNG_UST_ERR_EXITING && release_ret != -EPIPE) { + ERR("Error releasing app handle for app %d with ret %d", app->sock, release_ret); + } goto rcu_error; } /* Zero the new memory */ @@ -3554,6 +3655,11 @@ int ust_app_list_event_fields(struct lttng_event_field **fields) tmp_event[count].event.enabled = -1; count++; } + ret = ustctl_release_handle(app->sock, handle); + pthread_mutex_unlock(&app->sock_lock); + if (ret != -LTTNG_UST_ERR_EXITING && ret != -EPIPE) { + ERR("Error releasing app handle for app %d with ret %d", app->sock, ret); + } } ret = count; @@ -4134,7 +4240,9 @@ int ust_app_start_trace(struct ltt_ust_session *usess, struct ust_app *app) skip_setup: /* This start the UST tracing */ + pthread_mutex_lock(&app->sock_lock); ret = ustctl_start_session(app->sock, ua_sess->handle); + pthread_mutex_unlock(&app->sock_lock); if (ret < 0) { if (ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) { ERR("Error starting tracing for app pid: %d (ret: %d)", @@ -4160,7 +4268,9 @@ skip_setup: health_code_update(); /* Quiescent wait after starting trace */ + pthread_mutex_lock(&app->sock_lock); ret = ustctl_wait_quiescent(app->sock); + pthread_mutex_unlock(&app->sock_lock); if (ret < 0 && ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) { ERR("UST app wait quiescent failed for app pid %d ret %d", app->pid, ret); @@ -4221,7 +4331,9 @@ int ust_app_stop_trace(struct ltt_ust_session *usess, struct ust_app *app) health_code_update(); /* This inhibits UST tracing */ + pthread_mutex_lock(&app->sock_lock); ret = ustctl_stop_session(app->sock, ua_sess->handle); + pthread_mutex_unlock(&app->sock_lock); if (ret < 0) { if (ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) { ERR("Error stopping tracing for app pid: %d (ret: %d)", @@ -4241,7 +4353,9 @@ int ust_app_stop_trace(struct ltt_ust_session *usess, struct ust_app *app) health_code_update(); /* Quiescent wait after stopping trace */ + pthread_mutex_lock(&app->sock_lock); ret = ustctl_wait_quiescent(app->sock); + pthread_mutex_unlock(&app->sock_lock); if (ret < 0 && ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) { ERR("UST app wait quiescent failed for app pid %d ret %d", app->pid, ret); @@ -4439,7 +4553,9 @@ static int destroy_trace(struct ltt_ust_session *usess, struct ust_app *app) health_code_update(); /* Quiescent wait after stopping trace */ + pthread_mutex_lock(&app->sock_lock); ret = ustctl_wait_quiescent(app->sock); + pthread_mutex_unlock(&app->sock_lock); if (ret < 0 && ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) { ERR("UST app wait quiescent failed for app pid %d ret %d", app->pid, ret); @@ -4826,7 +4942,9 @@ int ust_app_calibrate_glb(struct lttng_ust_calibrate *calibrate) health_code_update(); + pthread_mutex_lock(&app->sock_lock); ret = ustctl_calibrate(app->sock, calibrate); + pthread_mutex_unlock(&app->sock_lock); if (ret < 0) { switch (ret) { case -ENOSYS: diff --git a/src/bin/lttng-sessiond/ust-app.h b/src/bin/lttng-sessiond/ust-app.h index b62e218a0..27e3dd0e4 100644 --- a/src/bin/lttng-sessiond/ust-app.h +++ b/src/bin/lttng-sessiond/ust-app.h @@ -227,6 +227,8 @@ struct ust_app_session { */ struct ust_app { int sock; + pthread_mutex_t sock_lock; /* Protects sock protocol. */ + int notify_sock; pid_t pid; pid_t ppid; @@ -283,11 +285,7 @@ struct ust_app { #ifdef HAVE_LIBLTTNG_UST_CTL int ust_app_register(struct ust_register_msg *msg, int sock); -static inline -int ust_app_register_done(int sock) -{ - return ustctl_register_done(sock); -} +int ust_app_register_done(struct ust_app *app); int ust_app_version(struct ust_app *app); void ust_app_unregister(int sock); int ust_app_start_trace_all(struct ltt_ust_session *usess); @@ -381,7 +379,7 @@ int ust_app_register(struct ust_register_msg *msg, int sock) return -ENOSYS; } static inline -int ust_app_register_done(int sock) +int ust_app_register_done(struct ust_app *app) { return -ENOSYS; } diff --git a/src/bin/lttng-sessiond/ust-consumer.c b/src/bin/lttng-sessiond/ust-consumer.c index 27ebf7d23..7317b64ef 100644 --- a/src/bin/lttng-sessiond/ust-consumer.c +++ b/src/bin/lttng-sessiond/ust-consumer.c @@ -400,7 +400,9 @@ int ust_consumer_send_stream_to_ust(struct ust_app *app, DBG2("UST consumer send stream to app %d", app->sock); /* Relay stream to application. */ + pthread_mutex_lock(&app->sock_lock); ret = ustctl_send_stream_to_ust(app->sock, channel->obj, stream->obj); + pthread_mutex_unlock(&app->sock_lock); if (ret < 0) { if (ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) { ERR("ustctl send stream handle %d to app pid: %d with ret %d", @@ -435,7 +437,9 @@ int ust_consumer_send_channel_to_ust(struct ust_app *app, app->sock, app->pid, channel->name, channel->tracing_channel_id); /* Send stream to application. */ + pthread_mutex_lock(&app->sock_lock); ret = ustctl_send_channel_to_ust(app->sock, ua_sess->handle, channel->obj); + pthread_mutex_unlock(&app->sock_lock); if (ret < 0) { if (ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) { ERR("Error ustctl send channel %s to app pid: %d with ret %d", diff --git a/src/bin/lttng-sessiond/ust-ctl.h b/src/bin/lttng-sessiond/ust-ctl.h index c2ab24ac9..5a1bb669d 100644 --- a/src/bin/lttng-sessiond/ust-ctl.h +++ b/src/bin/lttng-sessiond/ust-ctl.h @@ -24,6 +24,8 @@ #include +struct ust_app; + /* * FIXME: temporary workaround: we use a lttng-tools local version of * lttng-ust-abi.h if UST is not found. Eventually, we should use our @@ -36,11 +38,7 @@ #include #include -static inline -int ust_ctl_release_object(int sock, struct lttng_ust_object_data *data) -{ - return ustctl_release_object(sock, data); -} +int ust_app_release_object(struct ust_app *app, struct lttng_ust_object_data *data); #else /* HAVE_LIBLTTNG_UST_CTL */ @@ -49,7 +47,7 @@ int ust_ctl_release_object(int sock, struct lttng_ust_object_data *data) #include "lttng-ust-error.h" static inline -int ust_ctl_release_object(int sock, struct lttng_ust_object_data *data) +int ust_app_release_object(struct ust_app *app, struct lttng_ust_object_data *data) { return 0; } -- 2.34.1