public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Joerg Vehlow <lkml@jv-coder.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v3 3/4] lib: ignore SIGINT in _tst_kill_test
Date: Tue, 11 May 2021 07:54:07 +0200	[thread overview]
Message-ID: <dfdd8e9a-90ca-642d-1c21-da169ca3878f@jv-coder.de> (raw)
In-Reply-To: <20210508055109.16914-4-liwang@redhat.com>

Hi Li,

first of all thanks for fixing my patchset and getting it merged.

On 5/8/2021 7:51 AM, Li Wang wrote:
> We have to guarantee _tst_kill_test alive for a while to check if
> the target test eixst or not, so ignore SIGINT in _tst_kill_test
> is necessary, otherwise it will be stopped by the SIGINT sending
> by itself.
>
> The timeout03.sh verify this mechanism proccess well in output:
>
>    timeout03 1 TBROK: Test timeouted, sending SIGINT! If you are running on slow machine, try exporting LTP_TIMEOUT_MUL > 1
>    timeout03 1 TBROK: test interrupted or timed out
>    timeout03 1 TPASS: test run cleanup after timeout
>    timeout03 1 TINFO: Test is still running, waiting 10s
>    timeout03 1 TINFO: Test is still running, waiting 9s
>    timeout03 1 TINFO: Test is still running, waiting 8s
>    timeout03 1 TINFO: Test is still running, waiting 7s
>    timeout03 1 TINFO: Test is still running, waiting 6s
>    timeout03 1 TINFO: Test is still running, waiting 5s
>    timeout03 1 TINFO: Test is still running, waiting 4s
>    timeout03 1 TINFO: Test is still running, waiting 3s
>    timeout03 1 TINFO: Test is still running, waiting 2s
>    timeout03 1 TINFO: Test is still running, waiting 1s
>    timeout03 1 TBROK: Test still running, sending SIGKILL
>    Killed
At first I did bot understand the problem you found, because I tried 
with dash, busybox sh and zsh.
All three shells had no problem here. But then I tried with bash and it 
failed.

I wonder if this is a bug in bash or in the other shells. I guess 
sending the signal to the whole
process group should also send it to the process running _tst_kill_test.

I did some digging into this while writing this (see conclusion below 
for results only):
1. All shells have their own implementation of kill (compare <SHELL> -c 
kill with /usr/bin kill)
2. When replacing "just" kill in the script with /usr/bin/kill, it still 
only fails in bash.
3. zsh seems to ignore SIGINT, but it can be caught using trap. busybox 
sh, and dash can't even get it when trapped
4. zsh disables SIGINT by callling "trap '' INT" internally somehow. 
When resetting SIGINT to default behavior, it is the same as bash.

For zsh this seems to be default behavior for background processes, 
probably to prevent keyboard interruption by CTRL+C:
zsh -c "trap&"
trap -- '' INT
trap -- '' QUIT

zsh -c "trap"
# No output



To conclude:
- bash does not seem to care about SIGINT delivery to background 
processes, but can be blocked using trap
- zsh ignores SIGINT for background processes by default, but can be 
allowed using trap
- dash and busybox sh ignore the signal to background processes, and 
this cannot be changed with trap

I tried with the following snippets:
<SHELL> -c 'trap "echo trap;" INT; (sleep 2; echo end sub) & sleep 1; 
kill -INT -$$; echo end main'
<SHELL> -c 'trap "echo trap;" INT; (trap - SIGINT sleep 2; echo end sub) 
& sleep 1; kill -INT -$$; echo end main'
<SHELL> -c 'trap "echo trap;" INT; (trap "exit" SIGINT sleep 2; echo end 
sub) & sleep 1; kill -INT -$$; echo end main'

SIGINT handling for child processes is strange. This might have some 
implication for the shell tests,
because it is possible, that SIGINT is not delivered to all processes 
and some may reside as orphans.
Since this can happen only in case of timeouts, I guess there is no real 
Problem.

A possible fix could be using SIGTERM instead of SIGINT. This signal 
does not seem to have some "intelligent" handling for background processes.
I do not know why LTP used SIGINT in the first place. My first thought 
would have been to use SIGTERM.? It is the way to "politely ask 
processes to terminate"

J?rg

  parent reply	other threads:[~2021-05-11  5:54 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-08  5:51 [LTP] [PATCH v3 3/4] lib: ignore SIGINT in _tst_kill_test Li Wang
2021-05-10 11:47 ` Cyril Hrubis
2021-05-11  5:54 ` Joerg Vehlow [this message]
2021-05-12  9:49   ` Li Wang
2021-05-12 10:34     ` Joerg Vehlow
2021-05-12 14:20     ` Petr Vorel
2021-05-13  5:08       ` Li Wang
2021-05-14  7:53         ` Petr Vorel
2021-05-14  9:10           ` Li Wang
2021-05-14 15:10             ` Petr Vorel
2021-05-18  4:57         ` Joerg Vehlow
2021-05-18  7:27           ` Li Wang
2021-05-18  8:46             ` Petr Vorel
2021-05-18  9:45             ` Joerg Vehlow
2021-05-18 12:01               ` Li Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=dfdd8e9a-90ca-642d-1c21-da169ca3878f@jv-coder.de \
    --to=lkml@jv-coder.de \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox