[gnome-settings-daemon] common: Work around output buffering for g_debug



commit dee9a77f889c8f539bdfab77d9982e9358b8016d
Author: Benjamin Berg <bberg redhat com>
Date:   Thu Jan 11 15:55:32 2018 +0100

    common: Work around output buffering for g_debug
    
    During testing debug output is enabled using --verbose.
    Unfortunately the default logging handler in GLib is not flushing the
    utput stream for each log message. In addition, the default buffering
    for stdout seems to be block based (not line based) if stdout is not a
    TTY.
    This causes the log message to get stuck in the buffer and the tests
    cannot read them.
    
    See also https://bugzilla.gnome.org/show_bug.cgi?id=792432
    
    https://bugzilla.gnome.org/show_bug.cgi?id=792210

 plugins/common/daemon-skeleton-gtk.h |   12 +++++++++++-
 plugins/common/daemon-skeleton.h     |   12 +++++++++++-
 2 files changed, 22 insertions(+), 2 deletions(-)
---
diff --git a/plugins/common/daemon-skeleton-gtk.h b/plugins/common/daemon-skeleton-gtk.h
index 27aade6..2194b3d 100644
--- a/plugins/common/daemon-skeleton-gtk.h
+++ b/plugins/common/daemon-skeleton-gtk.h
@@ -212,8 +212,18 @@ main (int argc, char **argv)
 
         set_empty_gtk_theme (FALSE);
 
-        if (verbose)
+        if (verbose) {
                 g_setenv ("G_MESSAGES_DEBUG", "all", TRUE);
+                /* Work around GLib not flushing the output for us by explicitly
+                 * setting buffering to a sane behaviour. This is important
+                 * during testing when the output is not going to a TTY and
+                 * we are reading messages from g_debug on stdout.
+                 *
+                 * See also
+                 *  https://bugzilla.gnome.org/show_bug.cgi?id=792432
+                 */
+                setlinebuf (stdout);
+        }
 
        if (timeout > 0) {
                guint id;
diff --git a/plugins/common/daemon-skeleton.h b/plugins/common/daemon-skeleton.h
index e4641fc..367ac1e 100644
--- a/plugins/common/daemon-skeleton.h
+++ b/plugins/common/daemon-skeleton.h
@@ -185,8 +185,18 @@ main (int argc, char **argv)
 
        loop = g_main_loop_new (NULL, FALSE);
 
-        if (verbose)
+        if (verbose) {
                 g_setenv ("G_MESSAGES_DEBUG", "all", TRUE);
+                /* Work around GLib not flushing the output for us by explicitly
+                 * setting buffering to a sane behaviour. This is important
+                 * during testing when the output is not going to a TTY and
+                 * we are reading messages from g_debug on stdout.
+                 *
+                 * See also
+                 *  https://bugzilla.gnome.org/show_bug.cgi?id=792432
+                 */
+                setlinebuf (stdout);
+        }
 
        if (timeout > 0) {
                guint id;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]