From: Eric Biggers Date: Mon, 12 Jun 2017 21:15:28 +0000 (-0700) Subject: generic/397: be compatible with ignored SIGPIPE X-Git-Tag: v2022.05.01~2013 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=9bcb266cd778f8de9dab4b8c7e5664ddf50e888a;p=users%2Fhch%2Fxfstests-dev.git generic/397: be compatible with ignored SIGPIPE If generic/397 is executed in an environment with SIGPIPE ignored, it fails because the 'yes' program prints an error message: yes: standard output: Broken pipe yes: write error This can be reproduced with: trap '' SIGPIPE; ./check generic/397 Fix it by generating the string of 255 y's using just 'head' and 'tr' instead of 'yes', 'head', and 'tr'. Although it's not really a good idea to execute xfstests with SIGPIPE ignored, this is the only test I've noticed where it causes a problem, so it might as well be fixed in the test. It would be much nicer to prevent this problem for all tests by making the 'check' script restore the default SIGPIPE handler. But that isn't straightforward because bash's 'trap' builtin doesn't allow un-ignoring signals that were ignored on entry to the shell. [ eguan added more background infomation to commit log, which is also from Eric. I think it's an easy problem for others to run into, since sometimes processes ignore SIGPIPE because they want to get write errors instead, but then when doing fork() + exec() they forget to reset the SIGPIPE handler. Notably, Python got this wrong and it wasn't fixed until Python 3, so any programs executing the 'check' script from a Python 2 script will usually get this wrong (see: https://bugs.python.org/issue1652). And usually everything works fine but every once in a while there is a weird problem like this which has to be debugged. ] Signed-off-by: Eric Biggers Reviewed-by: Eryu Guan Signed-off-by: Eryu Guan --- diff --git a/tests/generic/397 b/tests/generic/397 index 7077d0483..ba9208913 100755 --- a/tests/generic/397 +++ b/tests/generic/397 @@ -69,7 +69,7 @@ for dir in $SCRATCH_MNT/edir $SCRATCH_MNT/ref_dir; do touch $dir/empty > /dev/null $XFS_IO_PROG -t -f -c "pwrite 0 4k" $dir/a > /dev/null $XFS_IO_PROG -t -f -c "pwrite 0 33k" $dir/abcdefghijklmnopqrstuvwxyz > /dev/null - maxname=$(yes | head -255 | tr -d '\n') # 255 character filename + maxname=$(head -c 255 /dev/zero | tr '\0' y) # 255 character filename $XFS_IO_PROG -t -f -c "pwrite 0 1k" $dir/$maxname > /dev/null ln -s a $dir/symlink ln -s abcdefghijklmnopqrstuvwxyz $dir/symlink2