Cygwin: Fix handling of wait pipe hangup by properly detecting EOF
[lttng-tools.git] / src / common / consumer.c
index 024ee17853c03c053dfa0ae4382a7e3763346b1f..c511494356369f59727467d835ef08e82bc99a19 100644 (file)
@@ -1046,30 +1046,45 @@ void *lttng_consumer_thread_poll_fds(void *data)
                        continue;
                }
 
-               /* Take care of high priority channels first. */
+
+               /* Check if each pipe has data. hack for cygwin. */
                for (i = 0; i < nb_fd; i++) {
-                       if (pollfd[i].revents & POLLPRI) {
-                               ssize_t len;
+                       if ((pollfd[i].revents & POLLIN) ||
+                                       local_stream[i]->hangup_flush_done) {
+                               int check_ret;
 
-                               DBG("Urgent read on fd %d", pollfd[i].fd);
-                               high_prio = 1;
-                               len = ctx->on_buffer_ready(local_stream[i], ctx);
-                               /* it's ok to have an unavailable sub-buffer */
-                               if (len < 0 && len != -EAGAIN) {
-                                       goto end;
-                               } else if (len > 0) {
-                                       local_stream[i]->data_read = 1;
+                               check_ret = lttng_consumer_check_pipe(local_stream[i], ctx);
+                               if (check_ret != 0) {
+                                       pollfd[i].revents |= POLLHUP;
                                }
                        }
                }
 
-               /*
-                * If we read high prio channel in this loop, try again
-                * for more high prio data.
-                */
-               if (high_prio) {
-                       continue;
-               }
+               /* Take care of high priority channels first. */
+               /* for (i = 0; i < nb_fd; i++) { */
+               /*      DBG("!!! POLL FLAGS: %d", pollfd[i].revents); */
+               /*      if (pollfd[i].revents & POLLPRI) { */
+               /*              ssize_t len; */
+
+               /*              DBG("Urgent read on fd %d", pollfd[i].fd); */
+               /*              high_prio = 1; */
+               /*              len = ctx->on_buffer_ready(local_stream[i], ctx); */
+               /*              /\* it's ok to have an unavailable sub-buffer *\/ */
+               /*              if (len < 0 && len != -EAGAIN) { */
+               /*                      goto end; */
+               /*              } else if (len > 0) { */
+               /*                      local_stream[i]->data_read = 1; */
+               /*              } */
+               /*      } */
+               /* } */
+
+               /* /\* */
+               /*  * If we read high prio channel in this loop, try again */
+               /*  * for more high prio data. */
+               /*  *\/ */
+               /* if (high_prio) { */
+               /*      continue; */
+               /* } */
 
                /* Take care of low priority channels. */
                for (i = 0; i < nb_fd; i++) {
@@ -1285,6 +1300,23 @@ ssize_t lttng_consumer_read_subbuffer(struct lttng_consumer_stream *stream,
        }
 }
 
+int lttng_consumer_check_pipe(struct lttng_consumer_stream *stream,
+               struct lttng_consumer_local_data *ctx)
+{
+       switch (consumer_data.type) {
+       case LTTNG_CONSUMER_KERNEL:
+               assert(0);
+               return -ENOSYS;
+       case LTTNG_CONSUMER32_UST:
+       case LTTNG_CONSUMER64_UST:
+               return lttng_ustconsumer_check_pipe(stream, ctx);
+       default:
+               ERR("Unknown consumer_data type");
+               assert(0);
+               return -ENOSYS;
+       }
+}
+
 int lttng_consumer_on_recv_stream(struct lttng_consumer_stream *stream)
 {
        switch (consumer_data.type) {
This page took 0.023552 seconds and 4 git commands to generate.