Rename consumer socket fd to fd_ptr
authorDavid Goulet <dgoulet@efficios.com>
Mon, 26 Aug 2013 19:18:44 +0000 (15:18 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Mon, 26 Aug 2013 19:40:13 +0000 (15:40 -0400)
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 <mathieu.desnoyers@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
src/bin/lttng-sessiond/cmd.c
src/bin/lttng-sessiond/consumer.c
src/bin/lttng-sessiond/consumer.h
src/bin/lttng-sessiond/kernel-consumer.c
src/bin/lttng-sessiond/kernel.c
src/bin/lttng-sessiond/main.c
src/bin/lttng-sessiond/ust-consumer.c

index dcb5da5f44864a84af1004669c760b6a77e5f06a..e5b2b7e3c8f606677d4bc03adfabf34691b20c52 100644 (file)
@@ -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);
index ee6f3c3ff8e9ddb5c614d6b9c60d5f2d592e21ff..d79dee3cafd99c1232f2458a985561fb0e7a1875 100644 (file)
@@ -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);
 
index eaa115333584d88e6edcfa3785b46ec3addf78d3..d9a78359926516cc311bc7ee5dc63f44bf080079 100644 (file)
@@ -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;
index 1405554d97cc04e2a466c74a8930d2deb27de0de..225e25856ab6e09d934e9bdf7f57b5e44f1496c7 100644 (file)
@@ -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);
 
index 5d4f61451a53cf3d2d6cd8da21feeec086ad9e94..5eda0775884cb93d7bbabe01df3e89c05659753a 100644 (file)
@@ -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
index 6c6386d2b3b1107255260110175743fa04ccf9bf..85904c812cdbab2f53ef0747014ad274a2e38ac4 100644 (file)
@@ -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");
                }
index f0e3ce92a192cbaad2e2b9f42a29f8a1e407eb42..78f29f497b7f69fb127bb24f78d7ce1a6f769654 100644 (file)
@@ -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;
This page took 0.035598 seconds and 4 git commands to generate.