Add a check for duplicate session fd
authorDavid Goulet <dgoulet@ev0ke.net>
Thu, 14 Jul 2011 20:01:37 +0000 (16:01 -0400)
committerDavid Goulet <david.goulet@polymtl.ca>
Thu, 14 Jul 2011 20:34:34 +0000 (16:34 -0400)
Signed-off-by: David Goulet <dgoulet@ev0ke.net>
liblttkconsumerd/liblttkconsumerd.c

index 742fddebe47304ab9def8c339f94c76b11e4d4e9..e4f5fe2e48323fa9ba2a8e7429501f65be03bc3d 100644 (file)
@@ -85,6 +85,30 @@ void kconsumerd_set_command_socket_path(char *sock)
        kconsumerd_command_sock_path = sock;
 }
 
+/*
+ * kconsumerd_find_session_fd
+ *
+ * Find a session fd in the global list.
+ *
+ * Return 1 if found else 0
+ */
+static int kconsumerd_find_session_fd(int fd)
+{
+       struct kconsumerd_fd *iter;
+
+       pthread_mutex_lock(&kconsumerd_lock_fds);
+       cds_list_for_each_entry(iter, &kconsumerd_fd_list.head, list) {
+               if (iter->sessiond_fd == fd) {
+                       DBG("Duplicate session fd %d", fd);
+                       pthread_mutex_unlock(&kconsumerd_lock_fds);
+                       return 1;
+               }
+       }
+       pthread_mutex_unlock(&kconsumerd_lock_fds);
+
+       return 0;
+}
+
 /*
  * kconsumerd_del_fd
  *
@@ -113,8 +137,14 @@ static void kconsumerd_del_fd(struct kconsumerd_fd *lcf)
  */
 static int kconsumerd_add_fd(struct lttcomm_kconsumerd_msg *buf, int consumerd_fd)
 {
-       struct kconsumerd_fd *tmp_fd;
        int ret;
+       struct kconsumerd_fd *tmp_fd;
+
+       /* Check if already exist */
+       ret = kconsumerd_find_session_fd(buf->fd);
+       if (ret == 1) {
+               goto end;
+       }
 
        tmp_fd = malloc(sizeof(struct kconsumerd_fd));
        tmp_fd->sessiond_fd = buf->fd;
@@ -576,7 +606,6 @@ static int kconsumerd_consumerd_recv_fd(int sfd, int size,
        }
 
 end:
-       DBG("kconsumerd_consumerd_recv_fd thread exiting");
        return ret;
 }
 
This page took 0.025542 seconds and 4 git commands to generate.