[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: [PATCH] timeout: Add support for "-k" parameter.
From:       Denys Vlasenko <vda.linux () googlemail ! com>
Date:       2021-12-17 22:10:26
Message-ID: CAK1hOcO+p106d0iS7xbPbHDPkmTbV=0W732qH9Mu3qjdc35c0A () mail ! gmail ! com
[Download RAW message or body]

On Sat, Oct 9, 2021 at 1:28 PM Matthew Slowe <foo@mafoo.org.uk> wrote:
> Add support for GNU coreutils "-k" parameter to timeout applet.
>
> This patch moves the timing and process checking code into a separate
> reusable function and adds a optional second timeout which will send a
> SIGKILL to the process if it's still alive.

                /* Just sleep(HUGE_NUM); kill(parent) may kill wrong process! */
-               while (1) {
-                       sleep1();
-                       if (--timeout <= 0)
-                               break;
-                       if (kill(parent, 0)) {
-                               /* process is gone */
+               if (timeout_wait(timeout, pid) == EXIT_SUCCESS)

You waiting for a wrong process: should be "parent", not "pid"
(pid is 0 here).

+                       return EXIT_SUCCESS;
+               kill(parent, signo);
+
+               if (kill_timeout > 0) {
+                       if (timeout_wait(kill_timeout, pid) == EXIT_SUCCESS)

Here too.

                                return EXIT_SUCCESS;
-                       }
+                       kill(parent, SIGKILL);
                }
-               kill(parent, signo);
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic