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 <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2021-03-08 13:28:41 +01:00
parent 7788000be0
commit 446d3972e5

View file

@ -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;