mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-20 04:19:25 +01:00
test-runner: use WNOHANG option waiting for PID
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).
This commit is contained in:
parent
6c9c65a5de
commit
f7c036a801
@ -624,14 +624,24 @@ exit:
|
|||||||
static void kill_process(pid_t pid)
|
static void kill_process(pid_t pid)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
l_debug("Terminate pid: %d", pid);
|
l_debug("Terminate pid: %d", pid);
|
||||||
|
|
||||||
kill(pid, SIGTERM);
|
kill(pid, SIGTERM);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
waitpid(pid, &status, 0);
|
if (waitpid(pid, &status, WNOHANG) == pid)
|
||||||
} while (!WIFEXITED(status) && !WIFSIGNALED(status));
|
return;
|
||||||
|
|
||||||
|
usleep(100000);
|
||||||
|
} while (!WIFEXITED(status) && !WIFSIGNALED(status) && i++ < 20);
|
||||||
|
|
||||||
|
l_error("Failed to kill process %d gracefully", pid);
|
||||||
|
kill(pid, SIGKILL);
|
||||||
|
|
||||||
|
/* SIGKILL shouldn't need WNOHANG */
|
||||||
|
waitpid(pid, &status, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool wait_for_socket(const char *socket, useconds_t wait_time)
|
static bool wait_for_socket(const char *socket, useconds_t wait_time)
|
||||||
|
Loading…
Reference in New Issue
Block a user