• Zhangjin Wu's avatar
    selftests/nolibc: test_fork: fix up duplicated print · ed495f09
    Zhangjin Wu authored
    running nolibc-test with glibc on x86_64 got such print issue:
    
        29 execve_root = -1 EACCES                                       [OK]
        30 fork30 fork = 0                                                      [OK]
        31 getdents64_root = 712                                         [OK]
    
    The fork test case has three printf calls:
    
        (1) llen += printf("%d %s", test, #name);
        (2) llen += printf(" = %d %s ", expr, errorname(errno));
        (3) llen += pad_spc(llen, 64, "[FAIL]\n"); --> vfprintf()
    
    In the following scene, the above issue happens:
    
        (a) The parent calls (1)
        (b) The parent calls fork()
        (c) The child runs and shares the print buffer of (1)
        (d) The child exits, flushs the print buffer and closes its own stdout/stderr
            * "30 fork" is printed at the first time.
        (e) The parent calls (2) and (3), with "\n" in (3), it flushs the whole buffer
            * "30 fork = 0 ..." is printed
    
    Therefore, there are two "30 fork" in the stdout.
    
    Between (a) and (b), if flush the stdout (and the sterr), the child in
    stage (c) will not be able to 'see' the print buffer.
    Signed-off-by: default avatarZhangjin Wu <falcon@tinylab.org>
    Reviewed-by: default avatarThomas Weißschuh <linux@weissschuh.net>
    Signed-off-by: default avatarWilly Tarreau <w@1wt.eu>
    Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
    ed495f09
nolibc-test.c 33.8 KB