#include "consumer.h"
+/*
+ * From a consumer_data structure, allocate and add a consumer socket to the
+ * consumer output.
+ *
+ * Return 0 on success, else negative value on error
+ */
+int consumer_create_socket(struct consumer_data *data,
+ struct consumer_output *output)
+{
+ int ret = 0;
+ struct consumer_socket *socket;
+
+ assert(data);
+
+ if (output == NULL || data->cmd_sock < 0) {
+ /*
+ * Not an error. Possible there is simply not spawned consumer or it's
+ * disabled for the tracing session asking the socket.
+ */
+ goto error;
+ }
+
+ rcu_read_lock();
+ socket = consumer_find_socket(data->cmd_sock, output);
+ rcu_read_unlock();
+ if (socket == NULL) {
+ socket = consumer_allocate_socket(data->cmd_sock);
+ if (socket == NULL) {
+ ret = -1;
+ goto error;
+ }
+
+ socket->lock = &data->lock;
+ rcu_read_lock();
+ consumer_add_socket(socket, output);
+ rcu_read_unlock();
+ }
+
+ DBG3("Consumer socket created (fd: %d) and added to output",
+ data->cmd_sock);
+
+error:
+ return ret;
+}
+
/*
* Find a consumer_socket in a consumer_output hashtable. Read side lock must
* be acquired before calling this function and across use of the
struct consumer_socket *socket = NULL;
/* Negative keys are lookup failures */
- if (key < 0) {
+ if (key < 0 || consumer == NULL) {
return NULL;
}
/*
* Set network URI to the consumer output object.
*
- * Return 0 on success. Negative value on error.
+ * Return 0 on success. Return 1 if the URI were equal. Else, negative value on
+ * error.
*/
int consumer_set_network_uri(struct consumer_output *obj,
struct lttng_uri *uri)
/* Assign default port. */
uri->port = DEFAULT_NETWORK_CONTROL_PORT;
}
+ DBG3("Consumer control URI set with port %d", uri->port);
break;
case LTTNG_STREAM_DATA:
dst_uri = &obj->dst.net.data;
/* Assign default port. */
uri->port = DEFAULT_NETWORK_DATA_PORT;
}
+ DBG3("Consumer data URI set with port %d", uri->port);
break;
default:
ERR("Set network uri type unknown %d", uri->stype);
if (!ret) {
/* Same URI, don't touch it and return success. */
DBG3("URI network compare are the same");
- goto end;
+ goto equal;
}
/* URIs were not equal, replacing it. */
DBG3("Consumer set network uri subdir path %s", tmp_path);
}
-end:
return 0;
-
+equal:
+ return 1;
error:
return -1;
}