Force tracked fd to be bigger than STDERR_FILENO
[lttng-ust.git] / liblttng-ust / lttng-ust-comm.c
index 511b9cf4a88214c0225ff8a7e15a63cbca32145e..32ba3c1d49e2ba7bbec27ffb2f0d3f502d168653 100644 (file)
@@ -1261,7 +1261,18 @@ char *get_map_shm(struct sock_info *sock_info)
                lttng_ust_unlock_fd_tracker();
                goto error;
        }
-       lttng_ust_add_fd_to_tracker(wait_shm_fd);
+
+       ret = lttng_ust_add_fd_to_tracker(wait_shm_fd);
+       if (ret < 0) {
+               ret = close(wait_shm_fd);
+               if (!ret) {
+                       PERROR("Error closing fd");
+               }
+               lttng_ust_unlock_fd_tracker();
+               goto error;
+       }
+
+       wait_shm_fd = ret;
        lttng_ust_unlock_fd_tracker();
 
        wait_shm_mmap = mmap(NULL, page_size, PROT_READ,
@@ -1353,7 +1364,7 @@ static
 void *ust_listener_thread(void *arg)
 {
        struct sock_info *sock_info = arg;
-       int sock, ret, prev_connect_failed = 0, has_waited = 0;
+       int sock, ret, prev_connect_failed = 0, has_waited = 0, fd;
        long timeout;
 
        lttng_ust_fixup_tls();
@@ -1433,9 +1444,21 @@ restart:
                ust_unlock();
                goto restart;
        }
-       lttng_ust_add_fd_to_tracker(ret);
-       lttng_ust_unlock_fd_tracker();
+       fd = ret;
+       ret = lttng_ust_add_fd_to_tracker(fd);
+       if (ret < 0) {
+               ret = close(fd);
+               if (ret) {
+                       PERROR("close on sock_info->socket");
+               }
+               ret = -1;
+               lttng_ust_unlock_fd_tracker();
+               ust_unlock();
+               goto quit;
+       }
+
        sock_info->socket = ret;
+       lttng_ust_unlock_fd_tracker();
 
        ust_unlock();
        /*
@@ -1504,9 +1527,22 @@ restart:
                ust_unlock();
                goto restart;
        }
-       lttng_ust_add_fd_to_tracker(ret);
-       lttng_ust_unlock_fd_tracker();
+
+       fd = ret;
+       ret = lttng_ust_add_fd_to_tracker(fd);
+       if (ret < 0) {
+               ret = close(fd);
+               if (ret) {
+                       PERROR("close on sock_info->notify_socket");
+               }
+               ret = -1;
+               lttng_ust_unlock_fd_tracker();
+               ust_unlock();
+               goto quit;
+       }
+
        sock_info->notify_socket = ret;
+       lttng_ust_unlock_fd_tracker();
 
        ust_unlock();
        /*
This page took 0.023269 seconds and 4 git commands to generate.