[LTP] [PATCH v2] lib: shell: Fix timeout process races

Li Wang liwang@redhat.com
Wed Sep 22 06:30:57 CEST 2021


On Tue, Sep 21, 2021 at 7:30 PM Cyril Hrubis <chrubis@suse.cz> wrote:

> 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.


--- 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) {


-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20210922/17bea4cd/attachment.htm>


More information about the ltp mailing list