X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fconsumer.c;h=3503e0415489636654d5a3fa037b4909a68907c3;hb=ad20f4747b375cf21623ece9f76c9a9b54c493bb;hp=7071974a16809d963fd830cee252ca43e2758305;hpb=173af62f4804133d4a7f45e34b6f72126f3eca5f;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/consumer.c b/src/bin/lttng-sessiond/consumer.c index 7071974a1..3503e0415 100644 --- a/src/bin/lttng-sessiond/consumer.c +++ b/src/bin/lttng-sessiond/consumer.c @@ -30,6 +30,51 @@ #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 @@ -43,7 +88,7 @@ struct consumer_socket *consumer_find_socket(int key, struct consumer_socket *socket = NULL; /* Negative keys are lookup failures */ - if (key < 0) { + if (key < 0 || consumer == NULL) { return NULL; } @@ -227,7 +272,8 @@ malloc_error: /* * 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) @@ -249,6 +295,7 @@ int consumer_set_network_uri(struct consumer_output *obj, /* 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; @@ -257,6 +304,7 @@ int consumer_set_network_uri(struct consumer_output *obj, /* 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); @@ -267,7 +315,7 @@ int consumer_set_network_uri(struct consumer_output *obj, 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. */ @@ -302,9 +350,9 @@ int consumer_set_network_uri(struct consumer_output *obj, DBG3("Consumer set network uri subdir path %s", tmp_path); } -end: return 0; - +equal: + return 1; error: return -1; }