X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fconsumer.c;h=344c6627dbbe507c01ba483c7ba46c8f2577b57c;hb=9d035200e9006c4d4cf6951c54641e06c0bdf2bc;hp=26ff56effe8f57715822badae8d8df2ade6c092e;hpb=3448e2667be7445ae7630a18c2ab32cb2bcdd174;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/consumer.c b/src/bin/lttng-sessiond/consumer.c index 26ff56eff..344c6627d 100644 --- a/src/bin/lttng-sessiond/consumer.c +++ b/src/bin/lttng-sessiond/consumer.c @@ -45,7 +45,11 @@ int consumer_recv_status_reply(struct consumer_socket *sock) assert(sock); ret = lttcomm_recv_unix_sock(sock->fd, &reply, sizeof(reply)); - if (ret < 0) { + if (ret <= 0) { + if (ret == 0) { + /* Orderly shutdown. Don't return 0 which means success. */ + ret = -1; + } /* The above call will print a PERROR on error. */ DBG("Fail to receive status reply on sock %d", sock->fd); goto end; @@ -372,10 +376,12 @@ struct consumer_output *consumer_copy_output(struct consumer_output *obj) /* Putting back the HT pointer and start copying socket(s). */ output->socks = tmp_ht_ptr; + rcu_read_lock(); cds_lfht_for_each_entry(obj->socks->ht, &iter.iter, socket, node.node) { /* Create new socket object. */ copy_sock = consumer_allocate_socket(socket->fd); if (copy_sock == NULL) { + rcu_read_unlock(); goto malloc_error; } @@ -383,6 +389,7 @@ struct consumer_output *consumer_copy_output(struct consumer_output *obj) copy_sock->lock = socket->lock; consumer_add_socket(copy_sock, output); } + rcu_read_unlock(); error: return output; @@ -789,6 +796,7 @@ int consumer_is_data_pending(unsigned int id, DBG3("Consumer data pending for id %u", id); /* Send command for each consumer */ + rcu_read_lock(); cds_lfht_for_each_entry(consumer->socks->ht, &iter.iter, socket, node.node) { /* Code flow error */ @@ -801,7 +809,7 @@ int consumer_is_data_pending(unsigned int id, /* The above call will print a PERROR on error. */ DBG("Error on consumer is data pending on sock %d", socket->fd); pthread_mutex_unlock(socket->lock); - goto error; + goto error_unlock; } /* @@ -810,11 +818,15 @@ int consumer_is_data_pending(unsigned int id, */ ret = lttcomm_recv_unix_sock(socket->fd, &ret_code, sizeof(ret_code)); - if (ret < 0) { + if (ret <= 0) { + if (ret == 0) { + /* Orderly shutdown. Don't return 0 which means success. */ + ret = -1; + } /* The above call will print a PERROR on error. */ DBG("Error on recv consumer is data pending on sock %d", socket->fd); pthread_mutex_unlock(socket->lock); - goto error; + goto error_unlock; } pthread_mutex_unlock(socket->lock); @@ -823,11 +835,13 @@ int consumer_is_data_pending(unsigned int id, break; } } + rcu_read_unlock(); DBG("Consumer data is %s pending for session id %u", ret_code == 1 ? "" : "NOT", id); return ret_code; -error: +error_unlock: + rcu_read_unlock(); return -1; }