- DBG2("UST consumer setup metadata channel key %lu", ua_chan->key);
-
- msg.cmd_type = LTTNG_CONSUMER_SETUP_METADATA;
- msg.u.setup_metadata.key = ua_chan->key;
-
- pthread_mutex_lock(socket->lock);
- health_code_update();
-
- ret = consumer_send_msg(socket, &msg);
- if (ret < 0) {
- goto error;
+ reg_uid = buffer_reg_uid_find(request.session_id,
+ request.bits_per_long, request.uid);
+ if (reg_uid) {
+ ust_reg = reg_uid->registry->reg.ust;
+ } else {
+ struct buffer_reg_pid *reg_pid =
+ buffer_reg_pid_find(request.session_id_per_pid);
+ if (!reg_pid) {
+ DBG("PID registry not found for session id %" PRIu64,
+ request.session_id_per_pid);
+
+ memset(&msg, 0, sizeof(msg));
+ msg.cmd_type = LTTNG_ERR_UND;
+ pthread_mutex_lock(socket->lock);
+ (void) consumer_send_msg(socket, &msg);
+ pthread_mutex_unlock(socket->lock);
+ /*
+ * This is possible since the session might have been destroyed
+ * during a consumer metadata request. So here, return gracefully
+ * because the destroy session will push the remaining metadata to
+ * the consumer.
+ */
+ ret = 0;
+ goto end;
+ }
+ ust_reg = reg_pid->registry->reg.ust;
+ }
+ assert(ust_reg);
+
+ pthread_mutex_lock(&ust_reg->lock);
+ ret_push = ust_app_push_metadata(ust_reg, socket, 1);
+ pthread_mutex_unlock(&ust_reg->lock);
+ if (ret_push == -EPIPE) {
+ DBG("Application or relay closed while pushing metadata");
+ } else if (ret_push < 0) {
+ ERR("Pushing metadata");
+ ret = -1;
+ goto end;
+ } else {
+ DBG("UST Consumer metadata pushed successfully");