Fix: lttng-live flush when output to file
[babeltrace.git] / formats / lttng-live / lttng-live-comm.c
index cea50ffdf7d62c5e3720ef010f5eb3f3d31d14d4..bfcef6905be4987d4ccee89dcb88ddf027766cf7 100644 (file)
@@ -246,7 +246,7 @@ void print_session_list(GPtrArray *session_list, const char *path)
 
        for (i = 0; i < session_list->len; i++) {
                relay_session = g_ptr_array_index(session_list, i);
-               fprintf(stdout, "%s/host/%s/%s (timer = %u, "
+               fprintf(LTTNG_LIVE_OUTPUT_FP, "%s/host/%s/%s (timer = %u, "
                                "%u stream(s), %u client(s) connected)\n",
                                path, relay_session->hostname,
                                relay_session->name, relay_session->timer,
@@ -649,6 +649,18 @@ retry:
                ret = -1;
                goto end;
        }
+
+       /*
+        * Flush the output between attempts to grab a packet, thus
+        * ensuring we flush at least at the periodical timer period.
+        * This ensures the output remains reactive for interactive users and
+        * that the output is flushed when redirected to a file by the shell.
+        */
+       if (fflush(LTTNG_LIVE_OUTPUT_FP) < 0) {
+               perror("fflush");
+               goto error;
+       }
+
        cmd.cmd = htobe32(LTTNG_VIEWER_GET_PACKET);
        cmd.data_size = htobe64(sizeof(rq));
        cmd.cmd_version = htobe32(0);
This page took 0.023925 seconds and 4 git commands to generate.