From 2db2f402a3bb0c948667c1401b733014fe90a718 Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Fri, 17 Mar 2006 14:07:34 +0000 Subject: mysql detection cleanup: fixes runtime linking, autodetection of main locations, detection of lib64 and different layouts git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1327 f882894a-f735-0410-b71e-b25c423dba1c --- REQUIREMENTS | 5 --- configure.in | 87 +++++++++++++++++++++++++++++---------------- plugins/Makefile.am | 2 ++ plugins/check_mysql.c | 4 +-- plugins/check_mysql_query.c | 4 +-- plugins/t/check_mysql.t | 2 +- 6 files changed, 63 insertions(+), 41 deletions(-) diff --git a/REQUIREMENTS b/REQUIREMENTS index 12552df4..f16de936 100644 --- a/REQUIREMENTS +++ b/REQUIREMENTS @@ -40,11 +40,6 @@ check_mysql, check_mysql_query: Redhat Powertools Source: mysql-3.20.32a-3.i386.rpm, mysql-devel-3.20.32a-3.i386.rpm (these seem to be broken, however) RPMS from www.mysql.org work better - If you use the Mac OS X package from mysql.org, you need to add two soft links for ./configure - to find the mysql libraries correctly: - cd /usr/local/mysql/lib && ln -s . mysql - cd /usr/local/mysql/include && ln -s . mysql - check_pqsql: - Requires the PostgreSQL libraries available from http://www.postgresql.org diff --git a/configure.in b/configure.in index d1ef9543..e02dc895 100644 --- a/configure.in +++ b/configure.in @@ -253,49 +253,72 @@ else fi LIBS="$_SAVEDLIBS" - dnl Check for mysql libraries _SAVEDLIBS="$LIBS" _SAVEDCPPFLAGS="$CPPFLAGS" +FOUNDMYSQL="no" AC_ARG_WITH(mysql, ACX_HELP_STRING([--with-mysql=DIR], - [sets path to mysql installation (assumes lib/mysql and include subdirs]), + [sets path to mysql installation (assumes lib/lib64 and include subdirs)]), MYSQL=$withval,) +# Find the mysql client libs if test -n "$MYSQL"; then + MYSQLLIBDIR=$MYSQL/lib + MYSQLLIB64DIR=$MYSQL/lib64 +elif test -f /usr/lib/libmysqlclient.so -o -f /usr/lib/libmysqlclient.a ; then + MYSQL="/usr" + MYSQLLIBDIR=$MYSQL/lib + MYSQLLIB64DIR=$MYSQL/lib64 +elif test -f /usr/lib/mysql/libmysqlclient.so -o -f /usr/lib/mysql/libmysqlclient.a ; then + MYSQL="/usr" MYSQLLIBDIR=$MYSQL/lib/mysql - CPPFLAGS="-I$MYSQL/include" - AC_CHECK_LIB(mysqlclient,mysql_init,MYSQLLIBS="-lmysqlclient -lz" check_mysql_LDFLAGS="-L$MYSQLLIBDIR " check_mysql_query_LDFLAGS="-L$MYSQLLIBDIR ",,-L$MYSQLLIBDIR -lz) - AC_CHECK_LIB(mysqlclient,mysql_close,MYSQLLIBS="-lmysqlclient") -elif test -f /usr/lib/libmysqlclient.so; then - AC_CHECK_LIB(mysqlclient,mysql_init,MYSQLLIBS="-lmysqlclient -lz",,-lz) - AC_CHECK_LIB(mysqlclient,mysql_close,MYSQLLIBS="-lmysqlclient") -elif test -f /usr/lib/libmysqlclient.a; then + MYSQLLIB64DIR=$MYSQL/lib64/mysql +elif test -f /usr/local/lib/libmysqlclient.so -o -f /usr/local/lib/libmysqlclient.a ; then + MYSQL="/usr/local" + MYSQLLIBDIR=$MYSQL/lib + MYSQLLIB64DIR=$MYSQL/lib64 +elif test -f /usr/local/lib/mysql/libmysqlclient.so -o -f /usr/local/lib/mysql/libmysqlclient.a ; then + MYSQL="/usr/local" + MYSQLLIBDIR=$MYSQL/lib/mysql + MYSQLLIB64DIR=$MYSQL/lib64/mysql +elif test -f /usr/local/mysql/lib/libmysqlclient.so -o -f /usr/local/mysql/lib/libmysqlclient.a ; then + MYSQL="/usr/local/mysql" + MYSQLLIBDIR=$MYSQL/lib + MYSQLLIB64DIR=$MYSQL/lib64 +fi + +# Check libs okay +if test -n "$MYSQL" ; then + CPPFLAGS="-L$MYSQLLIBDIR -L$MYSQLLIB64DIR" AC_CHECK_LIB(mysqlclient,mysql_init,MYSQLLIBS="-lmysqlclient -lz",,-lz) AC_CHECK_LIB(mysqlclient,mysql_close,MYSQLLIBS="-lmysqlclient") -elif test -f /usr/lib/mysql/libmysqlclient.so; then - AC_CHECK_LIB(mysqlclient,mysql_init,MYSQLLIBS="-lmysqlclient -lz" check_mysql_LDFLAGS="-L/usr/lib/mysql" check_mysql_query_LDFLAGS="-L/usr/lib/mysql",,-L/usr/lib/mysql -lz) - AC_CHECK_LIB(mysqlclient,mysql_close,MYSQLLIBS="-lmysqlclient" check_mysql_LDFLAGS="-L/usr/lib/mysql" check_mysql_query_LDFLAGS="-L/usr/lib/mysql",,-L/usr/lib/mysql) -elif test -f /usr/lib/mysql/libmysqlclient.a; then - AC_CHECK_LIB(mysqlclient,mysql_init,MYSQLLIBS="-lmysqlclient -lz" check_mysql_LDFLAGS="-L/usr/lib/mysql" check_mysql_query_LDFLAGS="-L/usr/lib/mysql",,-L/usr/lib/mysql -lz) - AC_CHECK_LIB(mysqlclient,mysql_close,MYSQLLIBS="-lmysqlclient" check_mysql_LDFLAGS="-L/usr/lib/mysql" check_mysql_query_LDFLAGS="-L/usr/lib/mysql",,-L/usr/lib/mysql) fi + +# Check headers okay if test "$ac_cv_lib_mysqlclient_mysql_init" = "yes" -o "$ac_cv_lib_mysqlclient_mysql_close" = "yes"; then - AC_CHECK_HEADERS(mysql/mysql.h mysql/errmsg.h, MYSQLINCLUDE="-I$MYSQL/include" ) - if test "$ac_cv_header_mysql_mysql_h" = "yes" -a "$ac_cv_header_mysql_errmsg_h" = "yes"; then - EXTRAS="$EXTRAS check_mysql check_mysql_query" - AC_SUBST(MYSQLINCLUDE) - AC_SUBST(MYSQLLIBS) - AC_SUBST(check_mysql_LDFLAGS) - AC_SUBST(check_mysql_query_LDFLAGS) - else - AC_MSG_WARN([Skipping mysql plugin]) - AC_MSG_WARN([install mysql client headers to compile this plugin (see REQUIREMENTS).]) + CPPFLAGS="-I$MYSQL/include" + AC_CHECK_HEADERS(mysql.h errmsg.h, FOUNDMYSQL="yes" MYSQLINCLUDE="-I$MYSQL/include") + if test x"$FOUNDMYSQL" != x"yes" ; then + AC_CHECK_HEADERS(mysql/mysql.h mysql/errmsg.h, FOUNDMYSQL="yes" MYSQLINCLUDE="-I$MYSQL/include/mysql") + fi +fi + +# Setup mysql plugins +if test $FOUNDMYSQL = "yes" ; then + EXTRAS="$EXTRAS check_mysql check_mysql_query" + if test -d $MYSQLLIB64DIR ; then + MYSQLLIBS="-L$MYSQLLIB64DIR -rpath $MYSQLLIB64DIR $MYSQLLIBS" + fi + if test -d $MYSQLLIBDIR ; then + MYSQLLIBS="-L$MYSQLLIBDIR -rpath $MYSQLLIBDIR $MYSQLLIBS" fi + AC_SUBST(MYSQLINCLUDE) + AC_SUBST(MYSQLLIBS) else AC_MSG_WARN([Skipping mysql plugin]) AC_MSG_WARN([install mysql client libs to compile this plugin (see REQUIREMENTS).]) fi -CPPFLAGS="$_SAVEDCPPFLAGS $MYSQLINCLUDE" +CPPFLAGS="$_SAVEDCPPFLAGS" LIBS="$_SAVEDLIBS" AC_CHECK_HEADERS(unistd.h) @@ -442,7 +465,7 @@ fi dnl openssl detection/configuration -if ! test "$with_openssl" = "no"; then +if ! test x"$with_openssl" = x"no"; then dnl Check for OpenSSL location if it wasn't already specified if ! test -d "$with_openssl"; then for d in $OPENSSL_DIRS; do @@ -456,18 +479,20 @@ if ! test "$with_openssl" = "no"; then _SAVEDLDFLAGS="$LDFLAGS" dnl Check for OpenSSL header files unset FOUNDINCLUDE - CPPFLAGS="$CPPFLAGS -I$OPENSSL/include" - LDFLAGS="$LDFLAGS -R$OPENSSL/lib" + if test x"$with_openssl" != x"/usr" ; then + CPPFLAGS="$CPPFLAGS -I$with_openssl/include" + LDFLAGS="$LDFLAGS -R$with_openssl/lib" + fi dnl check for openssl in $dir/include/openssl AC_CHECK_HEADERS(openssl/ssl.h openssl/x509.h openssl/rsa.h openssl/pem.h openssl/crypto.h openssl/err.h, - SSLINCLUDE="-I$OPENSSL/include" + SSLINCLUDE="-I$with_openssl/include" FOUNDINCLUDE=yes, FOUNDINCLUDE=no) dnl else check to see if $dir/include has it if test "$FOUNDINCLUDE" = "no"; then AC_CHECK_HEADERS(ssl.h x509.h rsa.h pem.h crypto.h err.h, - SSLINCLUDE="-I$OPENSSL/include" + SSLINCLUDE="-I$with_openssl/include" FOUNDINCLUDE=yes, FOUNDINCLUDE=no) fi diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 7f9d7456..9a1f6d09 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -63,7 +63,9 @@ check_ldap_LDADD = $(NETLIBS) $(LDAPLIBS) check_load_LDADD = $(BASEOBJS) popen.o check_mrtg_LDADD = $(BASEOBJS) check_mrtgtraf_LDADD = $(BASEOBJS) +check_mysql_CPPFLAGS = $(MYSQLINCLUDE) check_mysql_LDADD = $(NETLIBS) $(MYSQLLIBS) +check_mysql_query_CPPFLAGS = $(MYSQLINCLUDE) check_mysql_query_LDADD = $(NETLIBS) $(MYSQLLIBS) check_nagios_LDADD = $(BASEOBJS) runcmd.o check_nt_LDADD = $(NETLIBS) diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c index 92ac7ff0..9d547ddd 100644 --- a/plugins/check_mysql.c +++ b/plugins/check_mysql.c @@ -25,8 +25,8 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; #include "utils.h" #include "netutils.h" -#include -#include +#include +#include char *db_user = NULL; char *db_host = NULL; diff --git a/plugins/check_mysql_query.c b/plugins/check_mysql_query.c index 321af7aa..b542fb44 100644 --- a/plugins/check_mysql_query.c +++ b/plugins/check_mysql_query.c @@ -22,8 +22,8 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; #include "utils.h" #include "netutils.h" -#include -#include +#include +#include char *db_user = NULL; char *db_host = NULL; diff --git a/plugins/t/check_mysql.t b/plugins/t/check_mysql.t index 78413c6e..852926a7 100644 --- a/plugins/t/check_mysql.t +++ b/plugins/t/check_mysql.t @@ -48,7 +48,7 @@ SKIP: { $result = NPTest->testCmd("./check_mysql -H $mysqlserver $mysql_login_details"); cmp_ok( $result->return_code, '==', 0, "Login okay"); - $result = NPTest->testCmd("./check_mysql -H $mysqlserver -u dummy"); + $result = NPTest->testCmd("./check_mysql -H $mysqlserver -u dummy -pdummy"); cmp_ok( $result->return_code, '==', 2, "Login failure"); like( $result->output, $bad_login_output, "Expected login failure message"); -- cgit v1.2.3-74-g34f1