Re: 2.0.0-pre1 - cannot build on FreeBSD



Hi Nicolas,

In message <20070528110552.GC378@asuka.tech.sitadelle.com>, Nicolas Baradakis <nbk@sitadelle.com> writes
David Wood wrote:

I've put in quite a bit of work today towards porting 2.0.0-pre1 to
FreeBSD, with the intention of submitting a FreeRADIUS 2 port as soon as
possible.

Unfortunately, there's a problem which I don't have the autoconf skills
to patch quickly. When checking (and later attempting to use) net/if.h,
you need to #include sys/socket.h on FreeBSD to get the definition of
struct sockaddr.

Thanks for the report. I hope the following changes in CVS head will
solve the problem. (you also need to run autoconf)

That solves that problem - thanks. As you've committed that to the CVS head, the chances are that that problem is fixed for good - and it may help out on other BSD and BSD like operating systems.


Fortunately it's a two line change in the port's Makefile to delete configure after applying the patch and run configure.in through autoconf 2.61 - though if I don't need to do that, I don't, as it means that the port doesn't force systems without autoconf 2.61 to build and install autoconf.

That said, there's a problem in the 1.x port that I want to fix in 2.x (and eventually backport to 1.x) which will require me to patch configure.in - so I'll probably finish up depending on autoconf anyway.



Back to 2.0.0-pre1. Fixing that problem reveals another problem - src/lib/getaddrinfo.c (a new file in 2.x) attempts to redefine gethostbyaddr_r():

/usr/local/bin/libtool --mode=compile cc -O -pipe -march=pentium3 -I/usr/local/include -L/usr/local/lib -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS -Wall -D_GNU_SOURCE -DNDEBUG -D_LIBRADIUS -I/var/ports/usr/ports_updated/net/freeradius2/work/freeradius-server-2.0
.0-p
re1/src -c getaddrinfo.c
cc -O -pipe -march=pentium3 -I/usr/local/include -L/usr/local/lib -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS -Wall -D_GNU_SOURCE -DNDEBUG -D_LIBRADIUS -I/var/ports/usr/ports_updated/net/freeradius2/work/freeradius-server-2.0
.0-pre1/src -c getaddrinfo.c  -fPIC -DPIC -o .libs/getaddrinfo.o
getaddrinfo.c:159: error: conflicting types for 'gethostbyaddr_r'
/usr/include/netdb.h:225: error: previous declaration of 'gethostbyaddr_r' was here
getaddrinfo.c:159: error: conflicting types for 'gethostbyaddr_r'
/usr/include/netdb.h:225: error: previous declaration of 'gethostbyaddr_r' was here
getaddrinfo.c:26: warning: 'lrad_hostbyname' defined but not used
getaddrinfo.c:28: warning: 'lrad_hostbyname_mutex' defined but not used
getaddrinfo.c:159: warning: 'gethostbyaddr_r' defined but not used
gmake[4]: *** [getaddrinfo.lo] Error 1


There's a comment in configure.in, at line 900 (after applying your patch), about Tru64 having a BSD style function gethostbyaddr_r() function that's thread safe. The same is true of FreeBSD now - the BSD style gethostbyaddr_r() function is thread safe on FreeBSD since at least FreeBSD 4.11. FreeBSD 4.x is now end of life, and the only supported versions of FreeBSD are 5.x and 6.x - with 7.x under development, so that means all supported (and even some legacy) versions of FreeBSD have a thread safe (but three argument BSD style) function built in.

The FreeBSD ports system has dropped support for 4.x, but I haven't removed the 4.x specific stuff from the FreeRADIUS 1.x port. I'm not going to support 4.x on FreeRADIUS 2.x, however - I would be very unlikely to get any new port with 4.x support committed now.

<http://www.freebsd.org/cgi/man.cgi?query=gethostbyname&apropos=0&sektion
=3&manpath=FreeBSD+6.2-RELEASE&format=html> is the reference to the appropriate man page - see the second paragraph under BUGS for the reference to thread safety.


The prototype for gethostbyaddr_r is included via #include <netdb.h>, which configure is picking up as available on FreeBSD. That's the same header as the C compiler is flagging up in the errors.


I suspect this problem will affect all other systems which finish up the configure run with #define GETHOSTBYADDRRSTYLE BSDSTYLE in confdefs.h and that also have a prototype for the built-in gethostbyaddr_r() netdb.h (or another header file that FreeRADIUS finishes up #including). The logic in src/lib/getaddrinfo.c makes this attempted redefinition near certain on many BSD and BSD-like systems:

#undef LOCAL_GETHOSTBYADDRR
#ifndef GETHOSTBYADDRRSTYLE
#define LOCAL_GETHOSTBYADDRR 1
#elif (GETHOSTBYADDRRSTYLE != SYSVSTYLE) && (GETHOSTBYADDRRSTYLE != GNUSTYLE)
#define LOCAL_GETHOSTBYADDRR 1
#endif /* GETHOSTBYADDRRSTYLE */

If GETHOSTBYADDRRSTYLE is BSDSTYLE, LOCAL_GETHOSTBYADDRR is #defined to 1, which means the block of code around line 180 that begins #ifdef LOCAL_GETHOSTBYADDRR will be compiled, attempting to redefine gethostbyaddr_r(). However, if GETHOSTBYADDRRSTYLE is BSDSTYLE rather than not defined, the chances are that you've already #included the header that contains the prototype for the system gethostbyaddr_r().



As an aside, FreeBSD 6.2-RELEASE-p4 i386, which is the OS on my development box, finishes up with #define GETHOSTBYNAMERSTYLE GNUSTYLE in confdefs.h - so there won't be a similar problem with redefining gethostbyname_r on FreeBSD - but there may be on other operating systems.



As this one doesn't involve autoconf, I could attempt to come up with a patch. I'm comfortable enough in C - it's autoconf that I lack experience with. However, I'd rather throw this back to the developers and let you come up with a solution that matches your design intent.


If you let me have a patch, I'll keep on testing. As always, let me know if you want any more information.



Best wishes,




David
--
David Wood
david@wood2.org.uk




This archive was generated by a fusion of Pipermail (Mailman edition) and MHonArc.