-/*
- * Command LTTNG_SET_CONSUMER_URI processed by the client thread.
- */
-static int cmd_set_consumer_uri(int domain, struct ltt_session *session,
- size_t nb_uri, struct lttng_uri *uris)
-{
- int ret, i;
- struct ltt_kernel_session *ksess = session->kernel_session;
- struct ltt_ust_session *usess = session->ust_session;
- struct consumer_output *consumer = NULL;
-
- assert(session);
- assert(uris);
- assert(nb_uri > 0);
-
- /* Can't enable consumer after session started. */
- if (session->enabled) {
- ret = LTTCOMM_TRACE_ALREADY_STARTED;
- goto error;
- }
-
- if (!session->start_consumer) {
- ret = LTTCOMM_NO_CONSUMER;
- goto error;
- }
-
- /*
- * This case switch makes sure the domain session has a temporary consumer
- * so the URL can be set.
- */
- switch (domain) {
- case 0:
- /* Code flow error. A session MUST always have a consumer object */
- assert(session->consumer);
- /*
- * The URL will be added to the tracing session consumer instead of a
- * specific domain consumer.
- */
- consumer = session->consumer;
- break;
- case LTTNG_DOMAIN_KERNEL:
- /* Code flow error if we don't have a kernel session here. */
- assert(ksess);
-
- /* Create consumer output if none exists */
- consumer = ksess->tmp_consumer;
- if (consumer == NULL) {
- consumer = consumer_copy_output(ksess->consumer);
- if (consumer == NULL) {
- ret = LTTCOMM_FATAL;
- goto error;
- }
- ksess->tmp_consumer = consumer;
- }
-
- break;
- case LTTNG_DOMAIN_UST:
- /* Code flow error if we don't have a kernel session here. */
- assert(usess);
-
- /* Create consumer output if none exists */
- consumer = usess->tmp_consumer;
- if (consumer == NULL) {
- consumer = consumer_copy_output(usess->consumer);
- if (consumer == NULL) {
- ret = LTTCOMM_FATAL;
- goto error;
- }
- usess->tmp_consumer = consumer;
- }
-
- break;
- }
-
- for (i = 0; i < nb_uri; i++) {
- struct consumer_socket *socket;
- struct lttng_ht_iter iter;
-
- ret = add_uri_to_consumer(consumer, &uris[i], domain);
- if (ret < 0) {
- goto error;
- }
-
- /*
- * Don't send relayd socket if URI is NOT remote or if the relayd
- * sockets for the session are already sent.
- */
- if (uris[i].dtype == LTTNG_DST_PATH ||
- consumer->dst.net.relayd_socks_sent) {
- continue;
- }
-
- /* Try to send relayd URI to the consumer if exist. */
- cds_lfht_for_each_entry(consumer->socks->ht, &iter.iter,
- socket, node.node) {
-
- /* A socket in the HT should never have a negative fd */
- assert(socket->fd >= 0);
-
- pthread_mutex_lock(socket->lock);
- ret = send_socket_relayd_consumer(domain, session, &uris[i],
- consumer, socket->fd);
- pthread_mutex_unlock(socket->lock);
- if (ret != LTTCOMM_OK) {
- goto error;
- }
- }
- }
-
- /* All good! */
- ret = LTTCOMM_OK;
-
-error:
- return ret;
-}
-