From: Cyril Hrubis <chrubis@suse.cz>
To: Li Wang <liwang@redhat.com>
Cc: LTP List <ltp@lists.linux.it>
Subject: Re: [LTP] [PATCH v2] lib: shell: Fix timeout process races
Date: Wed, 22 Sep 2021 11:02:29 +0200 [thread overview]
Message-ID: <YUrxJfAOO3+B8//7@yuki> (raw)
In-Reply-To: <CAEemH2e0kHun++Y2w99N68WAhjFdQkSvkF-1UaDxjbkA1sBrAw@mail.gmail.com>
Hi!
> > > This 'pid' is the parent shell process id, so it obviously that
> > > tst_timeout_kill
> > > process would get signal SIGTERM as well.
> > >
> > > I'm thinking maybe we should let tst_timeout_kill itself ignore SIGTERM
> > > otherwise we have no chance to perform the following double-check code?
> >
> > I guess that signal(SIGTERM, SIG_IGN) a the start of the main() should
> > fix it.
> >
>
> It works, but better put it behind of sleep(timeout).
>
> Because we still need to guarantee tst_timeout_kill can be
> stopped by _tst_cleanup_timer before timeout happening.
Right, of course we want the timeout killer to be killable before the
timeout.
> --- a/testcases/lib/tst_timeout_kill.c
> +++ b/testcases/lib/tst_timeout_kill.c
> @@ -44,6 +44,8 @@ int main(int argc, char *argv[])
> if (timeout)
> sleep(timeout);
>
> + signal(SIGTERM, SIG_IGN);
> +
> print_msg("Test timed out, sending SIGTERM!");
> print_msg("If you are running on slow machine, try exporting
> LTP_TIMEOUT_MUL > 1");
>
> @@ -57,12 +59,12 @@ int main(int argc, char *argv[])
>
> i = 10;
>
> - while (!kill(-pid, 0) && i-- > 0) {
> + while (!kill(pid, 0) && i-- > 0) {
> print_msg("Test is still running...");
> sleep(1);
> }
>
> - if (!kill(-pid, 0)) {
> + if (!kill(pid, 0)) {
> print_msg("Test is still running, sending SIGKILL");
> ret = kill(-pid, SIGKILL);
> if (ret) {
Hmm, and of course this does not work since the timeout kill process is
around. Maybe we should make this process a separate process group from
the start, what about calling setpgid(0, 0) instead of setting up the
signal handler? That way we can send the signals to the whole process
group and make sure everything has been cleaned up.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2021-09-22 9:02 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-20 12:21 [LTP] [PATCH v2] lib: shell: Fix timeout process races Cyril Hrubis
2021-09-20 16:11 ` Petr Vorel
2021-09-21 3:27 ` Li Wang
2021-09-21 11:30 ` Cyril Hrubis
2021-09-22 4:30 ` Li Wang
2021-09-22 9:02 ` Cyril Hrubis [this message]
2021-09-22 9:13 ` Li Wang
2021-09-22 9:21 ` Cyril Hrubis
2021-09-22 9:22 ` Li Wang
2021-09-22 9:31 ` Cyril Hrubis
2021-09-22 9:39 ` 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=YUrxJfAOO3+B8//7@yuki \
--to=chrubis@suse.cz \
--cc=liwang@redhat.com \
--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