Fix: missing mutex lock if relayd was not created
authorDavid Goulet <dgoulet@efficios.com>
Thu, 20 Dec 2012 01:37:14 +0000 (20:37 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Thu, 20 Dec 2012 01:37:17 +0000 (20:37 -0500)
Also add missing ret = -1 assignment on error in error path when adding
a relayd socket in the consumer.

Signed-off-by: David Goulet <dgoulet@efficios.com>
src/common/consumer.c

index 1e710ab3d9b80fefbbfe2aad58fd050e50d03444..63c98350a4772435b50a84ae4b0ac25f4e4f3455 100644 (file)
@@ -2759,6 +2759,7 @@ int consumer_add_relayd_socket(int net_seq_idx, int sock_type,
                relayd = consumer_allocate_relayd_sock_pair(net_seq_idx);
                if (relayd == NULL) {
                        lttng_consumer_send_error(ctx, LTTCOMM_CONSUMERD_OUTFD_ERROR);
                relayd = consumer_allocate_relayd_sock_pair(net_seq_idx);
                if (relayd == NULL) {
                        lttng_consumer_send_error(ctx, LTTCOMM_CONSUMERD_OUTFD_ERROR);
+                       ret = -1;
                        goto error;
                }
                relayd->sessiond_session_id = (uint64_t) sessiond_id;
                        goto error;
                }
                relayd->sessiond_session_id = (uint64_t) sessiond_id;
@@ -2808,11 +2809,17 @@ int consumer_add_relayd_socket(int net_seq_idx, int sock_type,
                relayd->control_sock.fd = fd;
 
                /*
                relayd->control_sock.fd = fd;
 
                /*
-                * Create a session on the relayd and store the returned id. No need to
-                * grab the socket lock since the relayd object is not yet visible.
+                * Create a session on the relayd and store the returned id. Lock the
+                * control socket mutex if the relayd was NOT created before.
                 */
                 */
+               if (!relayd_created) {
+                       pthread_mutex_lock(&relayd->ctrl_sock_mutex);
+               }
                ret = relayd_create_session(&relayd->control_sock,
                                &relayd->relayd_session_id);
                ret = relayd_create_session(&relayd->control_sock,
                                &relayd->relayd_session_id);
+               if (!relayd_created) {
+                       pthread_mutex_unlock(&relayd->ctrl_sock_mutex);
+               }
                if (ret < 0) {
                        goto error;
                }
                if (ret < 0) {
                        goto error;
                }
@@ -2821,6 +2828,7 @@ int consumer_add_relayd_socket(int net_seq_idx, int sock_type,
                relayd_id_node = zmalloc(sizeof(struct consumer_relayd_session_id));
                if (!relayd_id_node) {
                        PERROR("zmalloc relayd id node");
                relayd_id_node = zmalloc(sizeof(struct consumer_relayd_session_id));
                if (!relayd_id_node) {
                        PERROR("zmalloc relayd id node");
+                       ret = -1;
                        goto error;
                }
 
                        goto error;
                }
 
@@ -2855,6 +2863,7 @@ int consumer_add_relayd_socket(int net_seq_idx, int sock_type,
                break;
        default:
                ERR("Unknown relayd socket type (%d)", sock_type);
                break;
        default:
                ERR("Unknown relayd socket type (%d)", sock_type);
+               ret = -1;
                goto error;
        }
 
                goto error;
        }
 
This page took 0.028134 seconds and 4 git commands to generate.