From: James Prestwood <prestwoj@gmail.com>
To: iwd@lists.01.org
Subject: [PATCH 1/1] test-runner: use WNOHANG option waiting for PID
Date: Tue, 16 Jun 2020 09:32:29 -0700 [thread overview]
Message-ID: <20200616163229.14429-2-prestwoj@gmail.com> (raw)
In-Reply-To: <20200616163229.14429-1-prestwoj@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1374 bytes --]
If an application has a bug and hangs on SIGTERM this causes
test-runner to hang as well. This is obviously an issue with
the application in question, but test-runner should have a way
of continuing onto the next test rather than hanging.
Instead we can use WNOHANG and a sleep to allow applications
some amount of time to exit, and if they haven't use SIGKILL
instead as well as print an error. Similar to how
wait_for_socket works. The timeout is hard coded to 2 seconds
(100ms sleep + 20 iterations).
---
tools/test-runner.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/tools/test-runner.c b/tools/test-runner.c
index f8677be5..498f3be3 100644
--- a/tools/test-runner.c
+++ b/tools/test-runner.c
@@ -626,14 +626,23 @@ exit:
static void kill_process(pid_t pid)
{
int status;
+ int i = 0;
l_debug("Terminate pid: %d", pid);
kill(pid, SIGTERM);
do {
- waitpid(pid, &status, 0);
- } while (!WIFEXITED(status) && !WIFSIGNALED(status));
+ if (waitpid(pid, &status, WNOHANG) == pid)
+ return;
+
+ usleep(100000);
+ } while (!WIFEXITED(status) && !WIFSIGNALED(status) && i++ < 20);
+
+ if (i >= 20) {
+ l_error("Failed to kill process %d gracefully", pid);
+ kill(pid, SIGKILL);
+ }
}
static bool wait_for_socket(const char *socket, useconds_t wait_time)
--
2.21.1
prev parent reply other threads:[~2020-06-16 16:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-16 16:32 [PATCH 0/1] Work around hanging ofono James Prestwood
2020-06-16 16:32 ` James Prestwood [this message]
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=20200616163229.14429-2-prestwoj@gmail.com \
--to=prestwoj@gmail.com \
--cc=iwd@lists.01.org \
/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