+ /* 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. */
+ pthread_mutex_lock(&app->sock_lock);
+ ret = lttng_ust_ctl_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) {
+ DBG3("UST app send stream to ust failed. Application is dead. (pid: %d, sock: %d).",
+ app->pid, app->sock);
+ } else if (ret == -EAGAIN) {
+ WARN("UST app send stream to ust failed. Communication time out (pid: %d, sock: %d).",
+ app->pid, app->sock);
+ } else {
+ ERR("UST app send stream, handle %d, to ust failed with ret %d (pid: %d, sock: %d).",
+ stream->obj->handle, ret, app->pid,
+ app->sock);