From: David Goulet Date: Mon, 26 Aug 2013 19:18:44 +0000 (-0400) Subject: Rename consumer socket fd to fd_ptr X-Git-Tag: v2.3.0-rc3~21 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=9363801e2d2069022a05e67066d8f527538946d0;p=lttng-tools.git Rename consumer socket fd to fd_ptr By renaming this value, first the name as a better semantic and second we are able to find every callsite that uses this variable thus making sure we don't forget any assert or check made on it. Acked-by: Mathieu Desnoyers Signed-off-by: David Goulet --- diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index dcb5da5f4..e5b2b7e3c 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -462,9 +462,6 @@ static int init_kernel_tracing(struct ltt_kernel_session *session) if (session->consumer_fds_sent == 0 && session->consumer != NULL) { cds_lfht_for_each_entry(session->consumer->socks->ht, &iter.iter, socket, node.node) { - /* Code flow error */ - assert(socket->fd); - pthread_mutex_lock(socket->lock); ret = kernel_consumer_send_session(socket, session); pthread_mutex_unlock(socket->lock); @@ -674,9 +671,6 @@ int cmd_setup_relayd(struct ltt_session *session) /* For each consumer socket, send relayd sockets */ cds_lfht_for_each_entry(usess->consumer->socks->ht, &iter.iter, socket, node.node) { - /* Code flow error */ - assert(socket->fd); - pthread_mutex_lock(socket->lock); ret = send_consumer_relayd_sockets(LTTNG_DOMAIN_UST, session->id, usess->consumer, socket); @@ -693,9 +687,6 @@ int cmd_setup_relayd(struct ltt_session *session) && ksess->consumer->enabled) { cds_lfht_for_each_entry(ksess->consumer->socks->ht, &iter.iter, socket, node.node) { - /* Code flow error */ - assert(socket->fd); - pthread_mutex_lock(socket->lock); ret = send_consumer_relayd_sockets(LTTNG_DOMAIN_KERNEL, session->id, ksess->consumer, socket); diff --git a/src/bin/lttng-sessiond/consumer.c b/src/bin/lttng-sessiond/consumer.c index ee6f3c3ff..d79dee3ca 100644 --- a/src/bin/lttng-sessiond/consumer.c +++ b/src/bin/lttng-sessiond/consumer.c @@ -48,11 +48,11 @@ int consumer_socket_send(struct consumer_socket *socket, void *msg, size_t len) ssize_t size; assert(socket); - assert(socket->fd); + assert(socket->fd_ptr); assert(msg); /* Consumer socket is invalid. Stopping. */ - fd = *socket->fd; + fd = *socket->fd_ptr; if (fd < 0) { goto error; } @@ -68,7 +68,7 @@ int consumer_socket_send(struct consumer_socket *socket, void *msg, size_t len) /* This call will PERROR on error. */ (void) lttcomm_close_unix_sock(fd); - *socket->fd = -1; + *socket->fd_ptr = -1; goto error; } @@ -92,11 +92,11 @@ int consumer_socket_recv(struct consumer_socket *socket, void *msg, size_t len) ssize_t size; assert(socket); - assert(socket->fd); + assert(socket->fd_ptr); assert(msg); /* Consumer socket is invalid. Stopping. */ - fd = *socket->fd; + fd = *socket->fd_ptr; if (fd < 0) { goto error; } @@ -112,7 +112,7 @@ int consumer_socket_recv(struct consumer_socket *socket, void *msg, size_t len) /* This call will PERROR on error. */ (void) lttcomm_close_unix_sock(fd); - *socket->fd = -1; + *socket->fd_ptr = -1; goto error; } @@ -203,7 +203,7 @@ int consumer_send_destroy_relayd(struct consumer_socket *sock, assert(consumer); assert(sock); - DBG2("Sending destroy relayd command to consumer sock %d", *sock->fd); + DBG2("Sending destroy relayd command to consumer sock %d", *sock->fd_ptr); msg.cmd_type = LTTNG_CONSUMER_DESTROY_RELAYD; msg.u.destroy_relayd.net_seq_idx = consumer->net_seq_index; @@ -378,7 +378,7 @@ struct consumer_socket *consumer_allocate_socket(int *fd) goto error; } - socket->fd = fd; + socket->fd_ptr = fd; lttng_ht_node_init_ulong(&socket->node, *fd); error: @@ -443,8 +443,8 @@ void consumer_destroy_socket(struct consumer_socket *sock) * consumer was registered, */ if (sock->registered) { - DBG3("Consumer socket was registered. Closing fd %d", *sock->fd); - lttcomm_close_unix_sock(*sock->fd); + DBG3("Consumer socket was registered. Closing fd %d", *sock->fd_ptr); + lttcomm_close_unix_sock(*sock->fd_ptr); } call_rcu(&sock->node.head, destroy_socket_rcu); @@ -575,13 +575,13 @@ int consumer_copy_sockets(struct consumer_output *dst, rcu_read_lock(); cds_lfht_for_each_entry(src->socks->ht, &iter.iter, socket, node.node) { /* Ignore socket that are already there. */ - copy_sock = consumer_find_socket(*socket->fd, dst); + copy_sock = consumer_find_socket(*socket->fd_ptr, dst); if (copy_sock) { continue; } /* Create new socket object. */ - copy_sock = consumer_allocate_socket(socket->fd); + copy_sock = consumer_allocate_socket(socket->fd_ptr); if (copy_sock == NULL) { rcu_read_unlock(); ret = -ENOMEM; @@ -714,13 +714,12 @@ int consumer_send_fds(struct consumer_socket *sock, int *fds, size_t nb_fd) assert(fds); assert(sock); - assert(sock->fd); assert(nb_fd > 0); - ret = lttcomm_send_fds_unix_sock(*sock->fd, fds, nb_fd); + ret = lttcomm_send_fds_unix_sock(*sock->fd_ptr, fds, nb_fd); if (ret < 0) { /* The above call will print a PERROR on error. */ - DBG("Error when sending consumer fds on sock %d", *sock->fd); + DBG("Error when sending consumer fds on sock %d", *sock->fd_ptr); goto error; } @@ -740,7 +739,6 @@ int consumer_send_msg(struct consumer_socket *sock, assert(msg); assert(sock); - assert(sock->fd); ret = consumer_socket_send(sock, msg, sizeof(struct lttcomm_consumer_msg)); if (ret < 0) { @@ -763,7 +761,6 @@ int consumer_send_channel(struct consumer_socket *sock, assert(msg); assert(sock); - assert(sock->fd); ret = consumer_send_msg(sock, msg); if (ret < 0) { @@ -915,7 +912,6 @@ int consumer_send_stream(struct consumer_socket *sock, assert(msg); assert(dst); assert(sock); - assert(sock->fd); assert(fds); ret = consumer_send_msg(sock, msg); @@ -948,7 +944,6 @@ int consumer_send_relayd_socket(struct consumer_socket *consumer_sock, assert(rsock); assert(consumer); assert(consumer_sock); - assert(consumer_sock->fd); /* Bail out if consumer is disabled */ if (!consumer->enabled) { @@ -967,7 +962,7 @@ int consumer_send_relayd_socket(struct consumer_socket *consumer_sock, msg.u.relayd_sock.session_id = session_id; memcpy(&msg.u.relayd_sock.sock, rsock, sizeof(msg.u.relayd_sock.sock)); - DBG3("Sending relayd sock info to consumer on %d", *consumer_sock->fd); + DBG3("Sending relayd sock info to consumer on %d", *consumer_sock->fd_ptr); ret = consumer_send_msg(consumer_sock, &msg); if (ret < 0) { goto error; @@ -1061,9 +1056,6 @@ int consumer_is_data_pending(uint64_t session_id, rcu_read_lock(); cds_lfht_for_each_entry(consumer->socks->ht, &iter.iter, socket, node.node) { - /* Code flow error */ - assert(socket->fd); - pthread_mutex_lock(socket->lock); ret = consumer_socket_send(socket, &msg, sizeof(msg)); if (ret < 0) { @@ -1109,7 +1101,6 @@ int consumer_flush_channel(struct consumer_socket *socket, uint64_t key) struct lttcomm_consumer_msg msg; assert(socket); - assert(socket->fd); DBG2("Consumer flush channel key %" PRIu64, key); @@ -1142,7 +1133,6 @@ int consumer_close_metadata(struct consumer_socket *socket, struct lttcomm_consumer_msg msg; assert(socket); - assert(socket->fd); DBG2("Consumer close metadata channel key %" PRIu64, metadata_key); @@ -1175,7 +1165,6 @@ int consumer_setup_metadata(struct consumer_socket *socket, struct lttcomm_consumer_msg msg; assert(socket); - assert(socket->fd); DBG2("Consumer setup metadata channel key %" PRIu64, metadata_key); @@ -1209,9 +1198,8 @@ int consumer_push_metadata(struct consumer_socket *socket, struct lttcomm_consumer_msg msg; assert(socket); - assert(socket->fd); - DBG2("Consumer push metadata to consumer socket %d", *socket->fd); + DBG2("Consumer push metadata to consumer socket %d", *socket->fd_ptr); msg.cmd_type = LTTNG_CONSUMER_PUSH_METADATA; msg.u.push_metadata.key = metadata_key; @@ -1224,7 +1212,8 @@ int consumer_push_metadata(struct consumer_socket *socket, goto end; } - DBG3("Consumer pushing metadata on sock %d of len %zu", *socket->fd, len); + DBG3("Consumer pushing metadata on sock %d of len %zu", *socket->fd_ptr, + len); ret = consumer_socket_send(socket, metadata_str, len); if (ret < 0) { @@ -1255,7 +1244,6 @@ int consumer_snapshot_channel(struct consumer_socket *socket, uint64_t key, struct lttcomm_consumer_msg msg; assert(socket); - assert(socket->fd); assert(output); assert(output->consumer); diff --git a/src/bin/lttng-sessiond/consumer.h b/src/bin/lttng-sessiond/consumer.h index eaa115333..d9a783599 100644 --- a/src/bin/lttng-sessiond/consumer.h +++ b/src/bin/lttng-sessiond/consumer.h @@ -35,9 +35,10 @@ enum consumer_dst_type { struct consumer_socket { /* * File descriptor. This is just a reference to the consumer data meaning - * that every access must be locked and check for a possible invalid value. + * that every access must be locked and checked for a possible invalid + * value. */ - int *fd; + int *fd_ptr; /* * To use this socket (send/recv), this lock MUST be acquired. @@ -94,8 +95,8 @@ struct consumer_data { /* * The metadata socket object is handled differently and only created * locally in this object thus it's the only reference available in the - * session daemon. For that reason, a static variable for the fd is - * required and the metadata socket fd points to it. + * session daemon. For that reason, a variable for the fd is required and + * the metadata socket fd points to it. */ int metadata_fd; struct consumer_socket metadata_sock; diff --git a/src/bin/lttng-sessiond/kernel-consumer.c b/src/bin/lttng-sessiond/kernel-consumer.c index 1405554d9..225e25856 100644 --- a/src/bin/lttng-sessiond/kernel-consumer.c +++ b/src/bin/lttng-sessiond/kernel-consumer.c @@ -371,7 +371,6 @@ int kernel_consumer_destroy_channel(struct consumer_socket *socket, assert(channel); assert(socket); - assert(socket->fd); DBG("Sending kernel consumer destroy channel key %d", channel->fd); @@ -400,7 +399,6 @@ int kernel_consumer_destroy_metadata(struct consumer_socket *socket, assert(metadata); assert(socket); - assert(socket->fd); DBG("Sending kernel consumer destroy channel key %d", metadata->fd); diff --git a/src/bin/lttng-sessiond/kernel.c b/src/bin/lttng-sessiond/kernel.c index 5d4f61451..5eda07758 100644 --- a/src/bin/lttng-sessiond/kernel.c +++ b/src/bin/lttng-sessiond/kernel.c @@ -863,8 +863,6 @@ int kernel_snapshot_record(struct ltt_kernel_session *ksess, socket, node.node) { struct consumer_output *saved_output; struct ltt_kernel_channel *chan; - /* Code flow error */ - assert(socket->fd); /* * Temporarly switch consumer output for our snapshot output. As long diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index 6c6386d2b..85904c812 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -690,9 +690,6 @@ static int update_kernel_stream(struct consumer_data *consumer_data, int fd) rcu_read_lock(); cds_lfht_for_each_entry(ksess->consumer->socks->ht, &iter.iter, socket, node.node) { - /* Code flow error */ - assert(socket->fd); - pthread_mutex_lock(socket->lock); ret = kernel_consumer_send_channel_stream(socket, channel, ksess, @@ -1030,7 +1027,7 @@ restart: signal_consumer_condition(consumer_data, -1); goto error; } - consumer_data->metadata_sock.fd = &consumer_data->metadata_fd; + consumer_data->metadata_sock.fd_ptr = &consumer_data->metadata_fd; /* Create metadata socket lock. */ consumer_data->metadata_sock.lock = zmalloc(sizeof(pthread_mutex_t)); if (consumer_data->metadata_sock.lock == NULL) { @@ -1173,8 +1170,8 @@ error: } consumer_data->cmd_sock = -1; } - if (*consumer_data->metadata_sock.fd >= 0) { - ret = close(*consumer_data->metadata_sock.fd); + if (*consumer_data->metadata_sock.fd_ptr >= 0) { + ret = close(*consumer_data->metadata_sock.fd_ptr); if (ret) { PERROR("close"); } diff --git a/src/bin/lttng-sessiond/ust-consumer.c b/src/bin/lttng-sessiond/ust-consumer.c index f0e3ce92a..78f29f497 100644 --- a/src/bin/lttng-sessiond/ust-consumer.c +++ b/src/bin/lttng-sessiond/ust-consumer.c @@ -207,7 +207,6 @@ int ust_consumer_ask_channel(struct ust_app_session *ua_sess, assert(ua_chan); assert(consumer); assert(socket); - assert(socket->fd); assert(registry); if (!consumer->enabled) { @@ -242,7 +241,6 @@ int ust_consumer_get_channel(struct consumer_socket *socket, assert(ua_chan); assert(socket); - assert(socket->fd); msg.cmd_type = LTTNG_CONSUMER_GET_CHANNEL; msg.u.get_channel.key = ua_chan->key; @@ -257,11 +255,11 @@ int ust_consumer_get_channel(struct consumer_socket *socket, } /* First, get the channel from consumer. */ - ret = ustctl_recv_channel_from_consumer(*socket->fd, &ua_chan->obj); + ret = ustctl_recv_channel_from_consumer(*socket->fd_ptr, &ua_chan->obj); if (ret < 0) { if (ret != -EPIPE) { ERR("Error recv channel from consumer %d with ret %d", - *socket->fd, ret); + *socket->fd_ptr, ret); } else { DBG3("UST app recv channel from consumer. Consumer is dead."); } @@ -280,7 +278,7 @@ int ust_consumer_get_channel(struct consumer_socket *socket, } /* Stream object is populated by this call if successful. */ - ret = ustctl_recv_stream_from_consumer(*socket->fd, &stream->obj); + ret = ustctl_recv_stream_from_consumer(*socket->fd_ptr, &stream->obj); if (ret < 0) { free(stream); if (ret == -LTTNG_UST_ERR_NOENT) { @@ -290,7 +288,7 @@ int ust_consumer_get_channel(struct consumer_socket *socket, } if (ret != -EPIPE) { ERR("Recv stream from consumer %d with ret %d", - *socket->fd, ret); + *socket->fd_ptr, ret); } else { DBG3("UST app recv stream from consumer. Consumer is dead."); } @@ -337,7 +335,6 @@ int ust_consumer_destroy_channel(struct consumer_socket *socket, assert(ua_chan); assert(socket); - assert(socket->fd); msg.cmd_type = LTTNG_CONSUMER_DESTROY_CHANNEL; msg.u.destroy_channel.key = ua_chan->key;