+ /* This MUST match or else we have a synchronization problem. */
+ assert(ua_chan->expected_stream_count == ua_chan->streams.count);
+
+ /* Wait for confirmation that we can proceed with the streams. */
+ ret = consumer_recv_status_reply(socket);
+ if (ret < 0) {
+ goto error;
+ }
+
+error:
+ health_code_update();
+ pthread_mutex_unlock(socket->lock);
+ return ret;
+}
+
+/*
+ * Send a destroy channel command to consumer using the given channel key.
+ *
+ * Note that this command MUST be used prior to a successful
+ * LTTNG_CONSUMER_GET_CHANNEL because once this command is done successfully,
+ * the streams are dispatched to the consumer threads and MUST be teardown
+ * through the hang up process.
+ *
+ * Return 0 on success else a negative value.
+ */
+int ust_consumer_destroy_channel(struct consumer_socket *socket,
+ struct ust_app_channel *ua_chan)
+{
+ int ret;
+ struct lttcomm_consumer_msg msg;
+
+ assert(ua_chan);
+ assert(socket);
+
+ memset(&msg, 0, sizeof(msg));
+ msg.cmd_type = LTTNG_CONSUMER_DESTROY_CHANNEL;
+ msg.u.destroy_channel.key = ua_chan->key;
+
+ pthread_mutex_lock(socket->lock);
+ health_code_update();
+
+ ret = consumer_send_msg(socket, &msg);
+ if (ret < 0) {
+ goto error;
+ }
+
+error:
+ health_code_update();
+ pthread_mutex_unlock(socket->lock);
+ return ret;
+}
+
+/*
+ * Send a given stream to UST tracer.
+ *
+ * On success return 0 else a negative value.
+ */
+int ust_consumer_send_stream_to_ust(struct ust_app *app,
+ struct ust_app_channel *channel, struct ust_app_stream *stream)
+{
+ int ret;
+
+ assert(app);
+ assert(stream);
+ assert(channel);
+
+ DBG2("UST consumer send stream to app %d", app->sock);
+
+ /* Relay stream to application. */
+ ret = ustctl_send_stream_to_ust(app->sock, channel->obj, stream->obj);
+ if (ret < 0) {
+ if (ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) {
+ ERR("ustctl send stream handle %d to app pid: %d with ret %d",
+ stream->obj->handle, app->pid, ret);
+ } else {
+ DBG3("UST app send stream to ust failed. Application is dead.");