./kselftest/prefix.pl read from pipe will block until the front command and its child processes all exit

From: lizhijian@xxxxxxxxxxx
Date: Mon Dec 20 2021 - 02:55:29 EST


Hi folks, Kees

This issue confuses the LKP/0Day robot for a long time.
Take below script as an example:

lizj@FNSTPC:~/workspace/colo/linux/tools/testing/selftests$ cat a.sh
#!/bin/bash
sleep 10 &
echo 1000000000000000

lizj@FNSTPC:~/workspace/colo/linux/tools/testing/selftests$ time ./a.sh | ./kselftest/prefix.pl
# 1000000000000000

real    0m10.004s
user    0m0.012s
sys    0m0.001s
------------------------------------

Although the first script already exited,  ./kselftest/prefix.pl will block until "sleep 10 &" exit.
That means once some of the child process cannot finish/exit itself, for example, one test
becomes *zombie* for some reasons, the whole ksefltest framework will hang forever.

In addition,  currently ksefltest timeout scheme[1][2] will not signal/kil the child processes, that
make the blocking often happens.

Since i'm not familiar with perl, not sure whether it can finish itself *directly* when first/front
command(excluding child processes) exits.


[1]: https://lkml.org/lkml/2021/12/17/140
[2]: http://lkml.iu.edu/hypermail/linux/kernel/2004.1/02379.html
$ man timeout
       --foreground
              when not running timeout directly from a shell prompt,
              allow COMMAND to read from the TTY and get TTY signals; in this mode, children of COMMAND will not be timed out


Thanks
Zhijian