views:

594

answers:

7

I have some old perl code which recently stopped working on a FreeBSD box. The code which fails looks (in simplest form) like this:

#!/usr/local/bin/perl -w

use strict;
use DBI;

my $datasource = "DBI:mysql:dbname:hostname.domain.com";
my $user = "username";
my $pass = "password";

DBI->connect($datasource, $user, $pass);

This fails with the following error:

/libexec/ld-elf.so.1: /usr/local/lib/mysql/libmysqlclient.so.15: Undefined symbol "gethostbyname_r"

If I change the datasource to reference "localhost" the code succeeds.

I've reinstalled mysql-client, DBI, and DBD-mysql from ports; no effect.

Other applications on this server (PHP, command line tools) are able to access mysql databases by hostname without trouble.

Suggestions for how to resolve this?

EDITED TO ADD: I notice that my box has both libmysqlclient.so.15 and libmysqlclient_r.so.15. Could the problem be that DBD::mysql is trying to use libmysqlclient when it should be using libmysqlclient_r? And if so, how to resolve?

+2  A: 

A shot in the dark:

gethostbyname**_r** indicates that Perl uses the "reentrant" (also called threaded/multi-threaded) version of the resolver code. Seems something is wrong with that.

When compiling the dependencies from the ports tree you often can switch multi-threadedness on or off. You can change you previous choice with make config from each ports application directory.

If you installed binary packages probably there is a version mismatch somewhere in there.

mdorseif
It sounds reasonable, but I'm not seeing a tunable option like that on any of the relevant ports.
davidcl
oh, and I don't use binary packages-- everything compiled from source in ports.
davidcl
See the edit at the bottom of my question for a possible lead on this.
davidcl
+1  A: 

'gethostbyname_r' is a GNU extension, and isn't part of the POSIX standard. Nevertheless, on my Freebsd 7 box, my libc includes it:

nm /usr/lib/libc.a | grep gethostbyname_r
00000eb0 T gethostbyname_r

Does your libc contains this symbol?

Nicolas Martyanoff
Yes:venture# nm /usr/lib/libc.a | grep gethostbyname_r00000744 T gethostbyname_r
davidcl
Then your libmysqlclient is built incorrectly. You should try other peoples' suggestions (recompiling the port, etc.).
Nicolas Martyanoff
As indicated, I've already recompiled the port several times with no effect.
davidcl
+1  A: 

Your version of libmysqlclient is out of date for your operating system version. Since it's in /usr/local, I assume it's compiled from source rather than installed. You can probably fix it by recompiling, but you might want to see if there is a supported version of mysql that can be installed through your OSes package manager.

Paul Tomblin
It's been recompiled without effect, and has been installed from FreeBSD ports, which should indicate it is supported for my OS version. Also, as mentioned in the question, PHP and command line apps don't have this problem, only perl.
davidcl
Are php and perl using the same .so.15, or is perl perhaps linked against an obsolete version? Perhaps it's perl that needs upgrading?
Paul Tomblin
+1  A: 

Try re-installing DBD-mysql from ports after temporarily moving /usr/local/lib/mysql/libmysqlclient.so.15 and /usr/local/lib/mysql/libmysqlclient.a out of the way (rename it or something). This might force DBD-mysql to link with the libmysqlclient_r.

codelogic
Unfortunately when I do that, DBD::mysql refuses to install.
davidcl
Try again, with libmysqlclient.a a link to libmysqlclient_r.a.
ysth
+1  A: 

As a workaround, try adding hostname.domain.com to /etc/hosts, or explicitly looking up the IP address in your Perl code and using that instead.

ysth
A: 

Did you ever get this issue resolved? I have re-installed mysql and the perl libraries.. No dice. :(

Nope. I worked around it but it never went away.
davidcl
A: 
# ldd libmysqlclient.so.15
libmysqlclient.so.15:
        libcrypt.so.3 => /lib/libcrypt.so.3 (0x281bf000)
        libm.so.4 => /lib/libm.so.4 (0x281d7000)
        libz.so.3 => /lib/libz.so.3 (0x281ed000)

FreeBSD 6.4-p3, mysql-client installed from ports, reinstall not help with problem ;(

no libc in ldd output ;(

but mysql compiled correctly:

# ldd mysql
mysql:
        libreadline.so.6 => /lib/libreadline.so.6 (0x28089000)
        libncursesw.so.6 => /lib/libncursesw.so.6 (0x280b9000)
        libmysqlclient.so.15 => /usr/local/lib/mysql/libmysqlclient.so.15 (0x28102000)
        libcrypt.so.3 => /lib/libcrypt.so.3 (0x2815c000)
        libz.so.3 => /lib/libz.so.3 (0x28174000)
        libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0x28185000)
        libm.so.4 => /lib/libm.so.4 (0x28250000)
        libc.so.6 => /lib/libc.so.6 (0x28266000)
        libncurses.so.6 => /lib/libncurses.so.6 (0x2834d000)
Lucky SB