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 2/2] qtest: don't close listener socket in qtest_socket_accept
Date: Tue, 27 Oct 2026 12:56:47 +0100 [thread overview]
Message-ID: <87wlr373wg.fsf@pond.sub.org> (raw)
In-Reply-To: <20261026163849.1045894-3-berrange@redhat.com> ("Daniel P. Berrangé"'s message of "Mon, 26 Oct 2026 16:38:49 +0000")
Daniel P. Berrangé <berrange@redhat.com> writes:
> The listener FD passed into qtest_socket_accept should be
> considered owned by the caller, and thus is is inappropriate
> and unusual to close it in the method.
>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
> tests/qtest/libqtest.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
> index 50487739ef9..0f701679745 100644
> --- a/tests/qtest/libqtest.c
> +++ b/tests/qtest/libqtest.c
> @@ -134,7 +134,6 @@ static int qtest_socket_accept(QTestState *s, int sock)
> (void *)&timeout, sizeof(timeout))) {
> fprintf(stderr, "%s failed to set SO_RCVTIMEO: %s\n",
> __func__, strerror(errno));
> - close(sock);
> return -1;
> }
>
> @@ -142,7 +141,7 @@ static int qtest_socket_accept(QTestState *s, int sock)
> if (!qtest_probe_child(s)) {
> fprintf(stderr,
> "child process unexpectedly exited, skipping socket accept\n");
> - goto cleanup;
> + return -1;
This removes the need for initializing @ret. Observation, not a demand.
> }
>
> addrlen = sizeof(addr);
> @@ -156,9 +155,6 @@ static int qtest_socket_accept(QTestState *s, int sock)
> fprintf(stderr, "%s failed: %s\n", __func__, strerror(errno));
> }
>
> - cleanup:
> - close(sock);
> -
> return ret;
> }
>
> @@ -566,6 +562,8 @@ void qtest_connect(QTestState *s)
> unlink(socket_path);
> unlink(qmp_socket_path);
> g_assert(s->fd >= 0 && s->qmp_fd >= 0);
> + close(s->sock);
> + close(s->qmpsock);
> s->sock = s->qmpsock = -1;
> /* ask endianness of the target */
> s->big_endian = qtest_query_target_endianness(s);
> @@ -675,6 +673,7 @@ QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd)
>
> *sock_fd = qtest_socket_accept(qts, sock_fd_init);
>
> + close(sock_fd_init);
> unlink(sock_path);
> g_free(sock_path);
> rmdir(sock_dir);
Reviewed-by: Markus Armbruster <armbru@redhat.com>
prev parent reply other threads:[~2026-10-27 11:57 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
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 [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=87wlr373wg.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.