diff options
author | Stefan Berger <stefanb@linux.ibm.com> | 2023-01-12 09:34:13 -0500 |
---|---|---|
committer | Stefan Berger <stefanb@linux.ibm.com> | 2023-01-16 17:18:51 -0500 |
commit | 82df11e78d0baef7ffb7e7933c6fb830ffed087c (patch) | |
tree | 1b5f88c0bf39f98e16c888efc60a1976aaeb62d8 /tests | |
parent | fb7e7990342e59cf67dbd895c1a1e3fb1741df7a (diff) |
tests/qtest: Poll on waitpid() for a while before sending SIGKILL
To prevent getting stuck on waitpid() in case the target process does
not terminate on SIGTERM, poll on waitpid() for 30s and if the target
process has not changed state until then send a SIGKILL to it.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Message-id: 20230112143413.3979057-1-stefanb@linux.ibm.com
[PMM: changed TFR to RETRY_ON_EINTR]
Diffstat (limited to 'tests')
-rw-r--r-- | tests/qtest/libqtest.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index 5cb38f90da..6b2216cb20 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -49,6 +49,8 @@ # define DEV_NULL "nul" #endif +#define WAITPID_TIMEOUT 30 + typedef void (*QTestSendFn)(QTestState *s, const char *buf); typedef void (*ExternalSendFn)(void *s, const char *buf); typedef GString* (*QTestRecvFn)(QTestState *); @@ -202,8 +204,24 @@ void qtest_wait_qemu(QTestState *s) { #ifndef _WIN32 pid_t pid; + uint64_t end; + + /* poll for a while until sending SIGKILL */ + end = g_get_monotonic_time() + WAITPID_TIMEOUT * G_TIME_SPAN_SECOND; + + do { + pid = waitpid(s->qemu_pid, &s->wstatus, WNOHANG); + if (pid != 0) { + break; + } + g_usleep(100 * 1000); + } while (g_get_monotonic_time() < end); + + if (pid == 0) { + kill(s->qemu_pid, SIGKILL); + pid = RETRY_ON_EINTR(waitpid(s->qemu_pid, &s->wstatus, 0)); + } - pid = RETRY_ON_EINTR(waitpid(s->qemu_pid, &s->wstatus, 0)); assert(pid == s->qemu_pid); #else DWORD ret; |