mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-20 15:48:54 +02:00
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
This commit is contained in:
@@ -251,6 +251,16 @@ watcher_init (void)
|
|||||||
g_assert_not_reached ();
|
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 ())
|
switch (fork ())
|
||||||
{
|
{
|
||||||
case -1:
|
case -1:
|
||||||
|
Reference in New Issue
Block a user