From: Thomas Huth <thuth@redhat.com>
To: qemu-devel@nongnu.org,
"Daniel P . Berrange" <berrange@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [PATCH] tests/socket-helpers: Only fail socket protocol check if it is really necessary
Date: Tue, 8 Sep 2020 12:54:35 +0200 [thread overview]
Message-ID: <20200908105435.218715-1-thuth@redhat.com> (raw)
The tests/test-char test is currently always failing on my system since
socket_can_bind_connect("::1", PF_INET6) fails with EINVAL and thus
socket_check_protocol_support() is returning -1 for an error. But IPv4
is working fine. The logic in socket_check_protocol_support() seems to
be wrong here, if either IPv6 or IPv4 is working, we should not return
an error here. Thus rework the function to only return errors if both
checks failed.
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
tests/socket-helpers.c | 23 +++++++++--------------
1 file changed, 9 insertions(+), 14 deletions(-)
diff --git a/tests/socket-helpers.c b/tests/socket-helpers.c
index 19a51e887e..62a0e0f2d9 100644
--- a/tests/socket-helpers.c
+++ b/tests/socket-helpers.c
@@ -136,22 +136,17 @@ static int socket_can_bind_connect(const char *hostname, int family)
int socket_check_protocol_support(bool *has_ipv4, bool *has_ipv6)
{
- *has_ipv4 = *has_ipv6 = false;
+ int errv4, errv6;
- if (socket_can_bind_connect("127.0.0.1", PF_INET) < 0) {
- if (errno != EADDRNOTAVAIL) {
- return -1;
- }
- } else {
- *has_ipv4 = true;
- }
+ errv4 = socket_can_bind_connect("127.0.0.1", PF_INET);
+ *has_ipv4 = (errv4 == 0);
- if (socket_can_bind_connect("::1", PF_INET6) < 0) {
- if (errno != EADDRNOTAVAIL) {
- return -1;
- }
- } else {
- *has_ipv6 = true;
+ errv6 = socket_can_bind_connect("::1", PF_INET6);
+ *has_ipv6 = (errv6 == 0);
+
+ if (!*has_ipv4 && !*has_ipv6 &&
+ (errv4 != EADDRNOTAVAIL || errv6 != EADDRNOTAVAIL)) {
+ return -1;
}
return 0;
--
2.18.2
next reply other threads:[~2020-09-08 10:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-08 10:54 Thomas Huth [this message]
2020-09-08 11:07 ` [PATCH] tests/socket-helpers: Only fail socket protocol check if it is really necessary Daniel P. Berrangé
2020-09-08 11:27 ` Thomas Huth
2020-09-08 11:41 ` Daniel P. Berrangé
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=20200908105435.218715-1-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=berrange@redhat.com \
--cc=marcandre.lureau@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).