X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fconsumer.c;h=9ff4eceb2c84ba3469ef22a5c59b59e57ca16672;hp=7071974a16809d963fd830cee252ca43e2758305;hb=a4b92340642035d1eafeb1eead0ad01f64d2007d;hpb=eb4a2943f0cf59f2f33627c4fa6ed79300119328 diff --git a/src/bin/lttng-sessiond/consumer.c b/src/bin/lttng-sessiond/consumer.c index 7071974a1..9ff4eceb2 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; }