From: Daniel P. Berrangé <[email protected]> If the very first iteration of the loop breaks early due to the dead QEMU process, 'ret' is never initialized. Furthermore the listener socket is not closed on success and there is no error message printed if timing out after all iterations are complete. These problems were introduced by the recent refactoring to check QEMU is alive.
CID 1688281 Reported-by: Markus Armbruster <[email protected]> Fixes: c12ad5378739 ("qtest: fail fast when QEMU terminates early") Signed-off-by: Daniel P. Berrangé <[email protected]> Reviewed-by: Markus Armbruster <[email protected]> Signed-off-by: Fabiano Rosas <[email protected]> --- tests/qtest/libqtest.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index 22b0dc193c9..dcce889ccc1 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -119,7 +119,7 @@ static int qtest_socket_accept(QTestState *s, int sock) { struct sockaddr_un addr; socklen_t addrlen; - int ret; + int ret = -1; size_t i; #ifndef _WIN32 struct timeval timeout = { .tv_sec = 0, @@ -145,14 +145,13 @@ static int qtest_socket_accept(QTestState *s, int sock) addrlen = sizeof(addr); ret = accept(sock, (struct sockaddr *)&addr, &addrlen); - if (ret == -1) { - if (errno == EINTR || errno == EAGAIN) { - continue; - } else { - fprintf(stderr, "%s failed: %s\n", __func__, strerror(errno)); - } + if (ret == -1 && (errno == EINTR || errno == EAGAIN)) { + continue; } - return ret; + break; + } + if (ret == -1) { + fprintf(stderr, "%s failed: %s\n", __func__, strerror(errno)); } cleanup: -- 2.53.0
