Cygwin: Fix racy read to detect applications sockets close
[lttng-tools.git] / src / bin / lttng-sessiond / main.c
index d29de9d459fd6b3fbd0325ecf04111fbbbf10aae..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;
+
+                                       }
                                }
                        }
                }
@@ -3226,6 +3238,9 @@ static ssize_t cmd_list_channels(int domain, struct ltt_session *session,
                        nb_chan = session->kernel_session->channel_count;
                }
                DBG3("Number of kernel channels %zd", nb_chan);
+               if (nb_chan <= 0) {
+                       ret = LTTCOMM_KERN_CHAN_NOT_FOUND;
+               }
                break;
        case LTTNG_DOMAIN_UST:
                if (session->ust_session != NULL) {
@@ -3233,6 +3248,9 @@ static ssize_t cmd_list_channels(int domain, struct ltt_session *session,
                                        session->ust_session->domain_global.channels);
                }
                DBG3("Number of UST global channels %zd", nb_chan);
+               if (nb_chan <= 0) {
+                       ret = LTTCOMM_UST_CHAN_NOT_FOUND;
+               }
                break;
        default:
                *channels = NULL;
@@ -3250,6 +3268,8 @@ static ssize_t cmd_list_channels(int domain, struct ltt_session *session,
                list_lttng_channels(domain, session, *channels);
        } else {
                *channels = NULL;
+               /* Ret value was set in the domain switch case */
+               goto error;
        }
 
        return nb_chan;
This page took 0.024678 seconds and 4 git commands to generate.