From 446d3972e53dbbaf7dbd47768cbc189a98df1ba5 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Mon, 8 Mar 2021 13:28:41 +0100 Subject: [PATCH] test suite: fflush() before fork() Forking a process also duplicates the buffers of FILE*s. Thus, if there is pending data, both the parent and the child process will write things. This is seldom a good idea. This issue was not noticed so far since by default the test suite already calls fflush() a lot. However, when stdout and stderr are both not a tty (according to isatty(1) and isatty(2)), these flushes are skipped. The result is that the child process repeat the full output from the test suite starting with "Compiled against cairo 1.17.4, running on 1.17.4." To reproduce this problem run: ./cairo-test-suite 2>&1 | cat Fix this by flushing all the files that I managed to find before fork(). Thanks to Pekka Paalanen for helping me figure this out. Signed-off-by: Uli Schlachter --- test/cairo-test-runner.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/cairo-test-runner.c b/test/cairo-test-runner.c index 779addf5b..551a4e072 100644 --- a/test/cairo-test-runner.c +++ b/test/cairo-test-runner.c @@ -208,6 +208,9 @@ _cairo_test_runner_preamble (cairo_test_runner_t *runner, if (! runner->foreground) { pid_t pid; + /* fork() duplicates output buffers, so clear them */ + fflush (NULL); + switch ((pid = fork ())) { case -1: /* error */ return CAIRO_TEST_UNTESTED; @@ -234,6 +237,9 @@ _cairo_test_runner_draw (cairo_test_runner_t *runner, if (! runner->foreground) { pid_t pid; + /* fork() duplicates output buffers, so clear them */ + fflush (NULL); + switch ((pid = fork ())) { case -1: /* error */ return CAIRO_TEST_UNTESTED;