Christoph Biedl wrote...
Enhance ngircd's resolver to resolve 127.0.0.1 into "localhost" no matter what. To avoid surprises, this should be controllable by another command line option. Using LD_PRELOAD during the tests was a variant.
The latter seemed like the least intrusive approach, so I gave that a try.
Summary:
* Having the idea: Mere seconds. * Digging out the last LD_PRELOAD code I wrote some ten years ago: Less than a minute. * Re-writing the code, fix typos and other bugs, basic and successful testing: Say 30 minutes. * Integration into the auto* eco-system: Hours and hours, and still no avail.
So telling old news: Something is horribly broken in the entire auto* concept. This simply must not be that complicated. It's time to quote the "die autotools" book title joke again.
I hereby declare surrender. Could please somebody finish the job? Very likely this requires just one or two more changes to run as expected, at least on Linux systems. Perhaps the uname check requires more tuning or things like that.
Releated peeve: Debian is at autoconf-1.14 now, running autorconf aborts since "automatic de-ANSI-fication support has been removed", I expect this to cause more trouble in the future.
Christoph
--- a/src/testsuite/Makefile.am +++ b/src/testsuite/Makefile.am @@ -24,11 +24,20 @@ start-server1 stop-server1 ngircd-test1.conf \ start-server2 stop-server2 ngircd-test2.conf
+noinst_LTLIBRARIES = libpreload.la + +libpreload_la_SOURCES = \ + getnameinfo-preload.c + +libpreload_la_LDFLAGS = \ + -module -export-dynamic -avoid-version -shared + all:
clean-local: rm -rf logs tests *-test ngircd-test*.log procs.tmp tests-skipped.lst \ - T-ngircd1 ngircd-test1.motd T-ngircd2 ngircd-test2.motd + T-ngircd1 ngircd-test1.motd T-ngircd2 ngircd-test2.motd \ + getnameinfo-preload.o getnameinfo-preload.lo libpreload.la .libs/
maintainer-clean-local: rm -f Makefile Makefile.in Makefile.am --- a/src/testsuite/start-server.sh +++ b/src/testsuite/start-server.sh @@ -40,6 +40,13 @@ export MALLOC_CHECK_
# starting up test-server ... +if [ "$(uname)" = 'Linux' ] ; then + if [ "$LD_PRELOAD" ] ; then + export LD_PRELOAD="$PWD/getnameinfo-preload.o $LD_PRELOAD" +else + export LD_PRELOAD="$PWD/getnameinfo-preload.o" + fi +fi ./T-ngircd${id} -n -f ${srcdir}/ngircd-test${id}.conf $* \
ngircd-test${id}.log 2>&1 &
sleep 1 --- /dev/null +++ b/src/testsuite/getnameinfo-preload.c @@ -0,0 +1,53 @@ + +#define _GNU_SOURCE + +#include <arpa/inet.h> +#include <dlfcn.h> +#include <netdb.h> +#include <string.h> +#include <sys/socket.h> + +int getnameinfo ( + const struct sockaddr *sa, + socklen_t salen, + char *host, + socklen_t hostlen, + char *serv, + socklen_t servlen, + unsigned int flags +) +{ + int (*real_getnameinfo) ( + const struct sockaddr *, + socklen_t, + char *, + socklen_t, + char *, + socklen_t, + unsigned int + ); + static struct sockaddr_in localhost; + if (localhost.sin_family == 0) { + localhost.sin_family = AF_INET; + inet_pton(AF_INET, "127.0.0.1", &(localhost.sin_addr)); + } + + if (!(real_getnameinfo = dlsym (RTLD_NEXT, "getnameinfo"))) + return -1; + + if ( + flags == NI_NAMEREQD && + sa->sa_family == AF_INET && + memcmp ( + &((struct sockaddr_in *) sa)->sin_addr, + &localhost.sin_addr, + sizeof (localhost.sin_addr) + ) == 0 + ) { + /* shortcut to "localhost" */ + strncpy (host, "localhost", hostlen); + return 0; + } + /* forward */ + return (real_getnameinfo (sa, salen, host, hostlen, serv, servlen, flags)); +} --- a/configure.ac +++ b/configure.ac @@ -64,6 +65,7 @@
AC_PROG_AWK AC_PROG_INSTALL +AC_PROG_LIBTOOL AC_PROG_LN_S AC_PROG_MAKE_SET AC_PROG_MKDIR_P