[glib: 1/2] gtestdbus: Flush stdout and stderr before forking a monitor process




commit 1e21abf0c4db08548bb8bfc3088cc0816fbdcd81
Author: Philip Withnall <pwithnall endlessos org>
Date:   Mon Feb 15 10:33:32 2021 +0000

    gtestdbus: Flush stdout and stderr before forking a monitor process
    
    This is a workaround for the fact that forking without execing is not
    easy to do correctly, and `GTestDBus` doesn’t do it correctly. However,
    `GTestDBus` is de-facto deprecated and so putting any more effort in is
    a waste.
    
    This fixes an issue where a test would print duplicate output when
    outputting to a fully-buffered FD, such as a pipe. This is because the
    buffer is non-empty before the `fork()`, and ends up duplicated in the
    parent and child processes, both of which later flush the duplicated
    buffer contents.
    
    Diagnosed and fix suggested by Simon McVittie.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Fixes: #2322

 gio/gtestdbus.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
---
diff --git a/gio/gtestdbus.c b/gio/gtestdbus.c
index 9cfaadbf0..d362f9478 100644
--- a/gio/gtestdbus.c
+++ b/gio/gtestdbus.c
@@ -251,6 +251,16 @@ watcher_init (void)
           g_assert_not_reached ();
         }
 
+      /* flush streams to avoid buffers being duplicated in the child and
+       * flushed by both the child and parent later
+       *
+       * FIXME: This is a workaround for the fact that watch_parent() uses
+       * non-async-signal-safe API. See
+       * https://gitlab.gnome.org/GNOME/glib/-/issues/2322#note_1034330
+       */
+      fflush (stdout);
+      fflush (stderr);
+
       switch (fork ())
         {
         case -1:


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