From: Mathieu Desnoyers Date: Wed, 14 Nov 2018 22:49:21 +0000 (-0500) Subject: Fix: create_channel_per_pid: remove channel on error X-Git-Tag: v2.10.6~13 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=cebb8722faefb09c6cc102aae237275e96603a23;p=lttng-tools.git Fix: create_channel_per_pid: remove channel on error The notification system of the session daemon tracks the lifetime of per-pid buffers (in effect, channel keys) using two hooks: - the successful completion of create_channel_per_pid() - the deletion of the channel from an application's registry Multiple error paths in create_channel_per_pid() can leave a channel in an app's registry without notifying the notification system of its existence. When the channel is finally cleaned-up, the channel deletion hook will inform the notification system that the channel should be deleted, resulting in an error as that channel was previously unknown. This fix ensures we remove the application's channel from its registry on error (with the notify parameter set to 'false'), thus ensuring that the notification system never tracks the incomplete channel. Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c index 48da16b10..62a6e9c09 100644 --- a/src/bin/lttng-sessiond/ust-app.c +++ b/src/bin/lttng-sessiond/ust-app.c @@ -3012,7 +3012,7 @@ static int create_channel_per_pid(struct ust_app *app, if (ret < 0) { ERR("Error creating UST channel \"%s\" on the consumer daemon", ua_chan->name); - goto error; + goto error_remove_from_registry; } ret = send_channel_pid_to_ust(app, ua_sess, ua_chan); @@ -3020,7 +3020,7 @@ static int create_channel_per_pid(struct ust_app *app, if (ret != -ENOTCONN) { ERR("Error sending channel to application"); } - goto error; + goto error_remove_from_registry; } session = session_find_by_id(ua_sess->tracing_id); @@ -3043,9 +3043,13 @@ static int create_channel_per_pid(struct ust_app *app, if (cmd_ret != LTTNG_OK) { ret = - (int) cmd_ret; ERR("Failed to add channel to notification thread"); - goto error; + goto error_remove_from_registry; } +error_remove_from_registry: + if (ret) { + ust_registry_channel_del_free(registry, ua_chan->key, false); + } error: rcu_read_unlock(); return ret;