Cygwin: Fix racy read to detect applications sockets close
[lttng-tools.git] / src / bin / lttng-sessiond / main.c
index d735be833f4064e88d0cd801a45c6d781d618c55..236341d2737fc21e06d74509c4e13a7d945455d2 100644 (file)
@@ -1287,16 +1287,28 @@ static void *thread_manage_apps(void *data)
                                 * At this point, we know that a registered application made
                                 * the event at poll_wait.
                                 */
-                               if (revents & (LPOLLERR | LPOLLHUP | LPOLLRDHUP)) {
-                                       /* Removing from the poll set */
-                                       ret = lttng_poll_del(&events, pollfd);
-                                       if (ret < 0) {
-                                               goto error;
-                                       }
 
-                                       /* Socket closed on remote end. */
-                                       ust_app_unregister(pollfd);
-                                       break;
+                               if (revents & (LPOLLIN | LPOLLERR | LPOLLHUP | LPOLLRDHUP)) {
+                                       ssize_t readlen;
+                                       char dummy;
+
+                                       do {
+                                               readlen = recv(pollfd, &dummy, 1, MSG_PEEK);
+                                       } while (readlen == -1 && errno == EINTR);
+
+                                       /* Peer has performed an orderly shutdown */
+                                       if (readlen == 0) {
+                                               /* Removing from the poll set */
+                                               ret = lttng_poll_del(&events, pollfd);
+                                               if (ret < 0) {
+                                                       goto error;
+                                               }
+
+                                               /* Socket closed on remote end. */
+                                               ust_app_unregister(pollfd);
+                                               break;
+
+                                       }
                                }
                        }
                }
This page took 0.023956 seconds and 4 git commands to generate.