Skip to contentSkip to conversation

io: fix build on FreeBSD

PATCH In review Ed Maste 3 participants 7 messages Feb 25, 2016 – Feb 26, 2016

lore
Share & tools
lore

Ed Maste

author
#0 lore raw

PATCH 1/1 io: fix build on FreeBSD

EAI_ADDRFAMILY is obsolete and FreeBSD/s netdb.h does not provide a definition.

---
 tests/test-io-channel-socket.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tests/test-io-channel-socket.c +4 -1
index 0697363..f4dbd60 100644
@@ -63,7 +63,10 @@ static int check_protocol_support(bool *has_ipv4, bool *has_ipv6)
 
     gaierr = getaddrinfo("::1", NULL, &hints, &ai);
     if (gaierr != 0) {
-        if (gaierr == EAI_ADDRFAMILY ||
+        if (
+#ifdef EAI_ADDRFAMILY
+            gaierr == EAI_ADDRFAMILY ||
+#endif
             gaierr == EAI_FAMILY ||
             gaierr == EAI_NONAME) {
             *has_ipv6 = false;
Signature · 1 line
2.4.6
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Ed Maste

EAI_ADDRFAMILY is obsolete and FreeBSD/s netdb.h does not provide a definition.

---
 tests/test-io-channel-socket.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Copying qemu-trivial to pick up the patch

Quoted 20 lines
tests/test-io-channel-socket.c +4 -1
index 0697363..f4dbd60 100644
@@ -63,7 +63,10 @@ static int check_protocol_support(bool *has_ipv4, bool *has_ipv6)
 
     gaierr = getaddrinfo("::1", NULL, &hints, &ai);
     if (gaierr != 0) {
-        if (gaierr == EAI_ADDRFAMILY ||
+        if (
+#ifdef EAI_ADDRFAMILY
+            gaierr == EAI_ADDRFAMILY ||
+#endif
             gaierr == EAI_FAMILY ||
             gaierr == EAI_NONAME) {
             *has_ipv6 = false;
Signature · 1 line
2.4.6

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#2 lore raw
In reply to Ed Maste
Quoted 13 lines · Ed Maste

EAI_ADDRFAMILY is obsolete and FreeBSD/s netdb.h does not provide a definition.

---
 tests/test-io-channel-socket.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tests/test-io-channel-socket.c +0 -0
index 0697363..f4dbd60 100644

tests/test-io-channel-socket.c static int check_protocol_support(bool *has_ipv4, bool *has_ipv6) · line 70

Quoted 9 lines
tests/test-io-channel-socket.c +4 -1
@@ -63,7 +63,10 @@ static int check_protocol_support(bool *has_ipv4, bool *has_ipv6)
 
     gaierr = getaddrinfo("::1", NULL, &hints, &ai);
     if (gaierr != 0) {
-        if (gaierr == EAI_ADDRFAMILY ||
+        if (
+#ifdef EAI_ADDRFAMILY
+            gaierr == EAI_ADDRFAMILY ||
+#endif
             gaierr == EAI_FAMILY ||

I'm not the biggest-fan of mid-expression #ifdefs. Can we rewrite this to look more like:

#ifndef EAI_ADDRFAMILY
#define EAI_ADDRFAMILY EAI_FAMILY
#endif

and leave the conditional expression unchanged?

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#3 lore raw
Quoted 27 lines · Eric Blake
Quoted 13 lines · Ed Maste

EAI_ADDRFAMILY is obsolete and FreeBSD/s netdb.h does not provide a definition.

---
 tests/test-io-channel-socket.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tests/test-io-channel-socket.c +0 -0
index 0697363..f4dbd60 100644

tests/test-io-channel-socket.c static int check_protocol_support(bool *has_ipv4, bool *has_ipv6) · line 70

Quoted 9 lines
tests/test-io-channel-socket.c +4 -1
@@ -63,7 +63,10 @@ static int check_protocol_support(bool *has_ipv4, bool *has_ipv6)
 
     gaierr = getaddrinfo("::1", NULL, &hints, &ai);
     if (gaierr != 0) {
-        if (gaierr == EAI_ADDRFAMILY ||
+        if (
+#ifdef EAI_ADDRFAMILY
+            gaierr == EAI_ADDRFAMILY ||
+#endif
             gaierr == EAI_FAMILY ||

I'm not the biggest-fan of mid-expression #ifdefs. Can we rewrite this to look more like:

Quoted 5 lines

#ifndef EAI_ADDRFAMILY
#define EAI_ADDRFAMILY EAI_FAMILY
#endif

and leave the conditional expression unchanged?

I think that'll cause gcc 6 to whine about you checking the same value twice in the conditional, like how it complains that EWOULDBLOCK and EAGAIN are the same.

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#4 lore raw
Quoted 13 lines · Daniel P. Berrange
Quoted 13 lines

tests/test-io-channel-socket.c static int check_protocol_support(bool *has_ipv4, bool *has_ipv6) · line 70

Quoted 5 lines
tests/test-io-channel-socket.c +4 -0
+        if (
+#ifdef EAI_ADDRFAMILY
+            gaierr == EAI_ADDRFAMILY ||
+#endif
             gaierr == EAI_FAMILY ||

I'm not the biggest-fan of mid-expression #ifdefs. Can we rewrite this to look more like:

#ifndef EAI_ADDRFAMILY
#define EAI_ADDRFAMILY EAI_FAMILY
#endif

Quoted 5 lines
Quoted 1 line

and leave the conditional expression unchanged?

I think that'll cause gcc 6 to whine about you checking the same value twice in the conditional, like how it complains that EWOULDBLOCK and EAGAIN are the same.

Oh, right. That's annoying. What about:

#ifndef EAI_ADDRFAMILY
#define EAI_ADDRFAMILY 0
#endif

if ((EAI_ADDRFAMILY && gaierr == EAIADDRFAMILY) ||

    gaierr == EAI_FAMILY...

to shut up gcc 6, while still hoisting the preprocessor logic outside of the expression?

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#5 lore raw
Quoted 27 lines · Eric Blake
Quoted 13 lines · Daniel P. Berrange
Quoted 13 lines

tests/test-io-channel-socket.c static int check_protocol_support(bool *has_ipv4, bool *has_ipv6) · line 70

Quoted 5 lines
tests/test-io-channel-socket.c +4 -0
+        if (
+#ifdef EAI_ADDRFAMILY
+            gaierr == EAI_ADDRFAMILY ||
+#endif
             gaierr == EAI_FAMILY ||

I'm not the biggest-fan of mid-expression #ifdefs. Can we rewrite this to look more like:

#ifndef EAI_ADDRFAMILY
#define EAI_ADDRFAMILY EAI_FAMILY
#endif

Quoted 5 lines
Quoted 1 line

and leave the conditional expression unchanged?

I think that'll cause gcc 6 to whine about you checking the same value twice in the conditional, like how it complains that EWOULDBLOCK and EAGAIN are the same.

Oh, right. That's annoying. What about:

#ifndef EAI_ADDRFAMILY
#define EAI_ADDRFAMILY 0
#endif

Quoted 5 lines

if ((EAI_ADDRFAMILY && gaierr == EAIADDRFAMILY) ||

    gaierr == EAI_FAMILY...

to shut up gcc 6, while still hoisting the preprocessor logic outside of the expression?

To be honest, I think the preprocessor check inside the expression isn't a big deal and clearer than playing games like this.

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
author
#6 lore raw
Quoted 8 lines · Daniel P. Berrange
Quoted 7 lines · Eric Blake

Oh, right. That's annoying. What about:

#ifndef EAI_ADDRFAMILY
#define EAI_ADDRFAMILY 0
#endif

Quoted 8 lines
Quoted 5 lines

if ((EAI_ADDRFAMILY && gaierr == EAIADDRFAMILY) ||

    gaierr == EAI_FAMILY...

to shut up gcc 6, while still hoisting the preprocessor logic outside of the expression?

To be honest, I think the preprocessor check inside the expression isn't a big deal and clearer than playing games like this.

I wasn't a fan of putting the preprocessor check inside the expression either, but no clear and concise alternative came to mind. I think it's easier to see both intent and effect with the preoprocessor check than with the above.