All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: qemu-devel@nongnu.org,  Laurent Vivier <lvivier@redhat.com>,
	 Fabiano Rosas <farosas@suse.de>,
	 Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH v2 1/2] qtest: multiple fixes to socket_accept()
Date: Tue, 27 Oct 2026 12:56:29 +0100	[thread overview]
Message-ID: <87y0bj73wy.fsf@pond.sub.org> (raw)
In-Reply-To: <20261026163849.1045894-2-berrange@redhat.com> ("Daniel P. Berrangé"'s message of "Mon, 26 Oct 2026 16:38:48 +0000")

Daniel P. Berrangé <berrange@redhat.com> writes:

> 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 <armbru@redhat.com>
> Fixes: c12ad5378739 ("qtest: fail fast when QEMU terminates early")
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  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 9e7a2d43a18..50487739ef9 100644
> --- a/tests/qtest/libqtest.c
> +++ b/tests/qtest/libqtest.c
> @@ -121,7 +121,7 @@ static int qtest_socket_accept(QTestState *s, int sock)
>  {
>      struct sockaddr_un addr;
>      socklen_t addrlen;
> -    int ret;
> +    int ret = -1;

You need this to make [*] work.

>      size_t i;
>  #ifndef _WIN32
>      struct timeval timeout = { .tv_sec = 0,
> @@ -147,14 +147,13 @@ static int qtest_socket_accept(QTestState *s, int sock)
       for (i = 0; i < ACCEPT_RETRIES ; i++) {
           if (!qtest_probe_child(s)) {
               fprintf(stderr,
                       "child process unexpectedly exited, skipping socket accept\n");

[*] @ret comes from the initialization above in the first iteration
only.  In later iterations, it comes from assignment [**] below.

               goto cleanup;
           }
>  
>          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) {

@ret comes from [**], because the loop runs at least once
(ACCEPT_RETRIES is positive).

> +        fprintf(stderr, "%s failed: %s\n", __func__, strerror(errno));
>      }
>  
>   cleanup:

Reviewed-by: Markus Armbruster <armbru@redhat.com>



  reply	other threads:[~2026-10-27 11:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-26 16:38 [PATCH v2 0/2] qtst: fixes and improvements to socket_accept() Daniel P. Berrangé
2026-10-26 16:38 ` [PATCH v2 1/2] qtest: multiple fixes " Daniel P. Berrangé
2026-10-27 11:56   ` Markus Armbruster [this message]
2026-10-26 16:38 ` [PATCH v2 2/2] qtest: don't close listener socket in qtest_socket_accept Daniel P. Berrangé
2026-10-27 11:56   ` Markus Armbruster

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=87y0bj73wy.fsf@pond.sub.org \
    --to=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=farosas@suse.de \
    --cc=lvivier@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.