From f2491f9a1cfc261b21e475154a6bced37a28ea6e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ale=C5=A1=20K=C5=99enek?= Date: Thu, 21 Aug 2008 13:40:59 +0000 Subject: [PATCH] - compile-in SONAME of libmysqlclient.so, and insist on it at runtime - client version mismatch yields a warning only --- org.glite.lbjp-common.db/Makefile | 23 ++++++++++++----------- org.glite.lbjp-common.db/src/db.c | 18 ++++++------------ 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/org.glite.lbjp-common.db/Makefile b/org.glite.lbjp-common.db/Makefile index eb83e15..0fc856a 100644 --- a/org.glite.lbjp-common.db/Makefile +++ b/org.glite.lbjp-common.db/Makefile @@ -31,13 +31,10 @@ host_cpu:=${shell uname -m} ifeq (${host_cpu},x86_64) archlib:=lib64 endif -ifeq ($(shell test -f ${mysql_prefix}/${archlib}/libmysqlclient.so && echo ok),ok) - MYSQL_LIBPATH := "$(wildcard ${mysql_prefix}/${archlib}/libmysqlclient.so*) $(notdir $(wildcard ${mysql_prefix}/${archlib}/libmysqlclient.so*))" -endif -ifeq ($(shell test -f ${mysql_prefix}/${archlib}/mysql/libmysqlclient.so && echo ok),ok) - MYSQL_LIBPATH := "$(wildcard ${mysql_prefix}/${archlib}/mysql/libmysqlclient.so*) $(notdir $(wildcard ${mysql_prefix}/${archlib}/mysql/libmysqlclient.so*))" -endif -MYSQL_CPPFLAGS:=-I${mysql_prefix}/include -I${mysql_prefix}/include/mysql -DMYSQL_LIBPATH=\"${MYSQL_LIBPATH}\" + +MYSQL_SONAME:=$(shell lib=/dev/null; for dir in '' mysql; do lib=${mysql_prefix}/${archlib}/$$dir/libmysqlclient.so; [ -f $$lib ] && break; done; readelf -d $$lib | grep SONAME | sed 's/.*\(libmysqlclient.so.[0-9]\{1,\}\).*/\1/' || echo notfound ) + +MYSQL_CPPFLAGS:=-I${mysql_prefix}/include -I${mysql_prefix}/include/mysql -DMYSQL_SONAME=\"${MYSQL_SONAME}\" MYSQL_LIBS=-lz CFLAGS:= \ @@ -71,11 +68,15 @@ LTESTOBJS:=${TESTOBJS:.o=.lo} default all: compile doc -libglite_lbu_db.la: ${LOBJS} - if [ -z "${MYSQL_LIBPATH}" ]; then \ - echo "Warning: MySQL shared library not found!"; \ - sleep 15; \ +check_soname: + if [ "${MYSQL_SONAME}" = notfound ]; then \ + echo "MySQL shared library not found!"; \ + false; \ fi + +db.lo: check_soname + +libglite_lbu_db.la: ${LOBJS} ${LINK} -o $@ $< ${EXT_LIBS} libglite_lbu_dbtest.la: ${LTESTOBJS} diff --git a/org.glite.lbjp-common.db/src/db.c b/org.glite.lbjp-common.db/src/db.c index c944245..f60b3d9 100644 --- a/org.glite.lbjp-common.db/src/db.c +++ b/org.glite.lbjp-common.db/src/db.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -185,7 +186,6 @@ int glite_lbu_DBError(glite_lbu_DBContext ctx, char **text, char **desc) { int glite_lbu_InitDBContext(glite_lbu_DBContext *ctx) { int err = 0; unsigned int ver_u; - char *p, *libnames, *libname; *ctx = calloc(1, sizeof **ctx); if (!*ctx) return ENOMEM; @@ -193,14 +193,8 @@ int glite_lbu_InitDBContext(glite_lbu_DBContext *ctx) { /* dynamic load the mysql library */ pthread_mutex_lock(&db_handle.lock); if (!db_handle.lib) { - libnames = strdup(MYSQL_LIBPATH " libmysqlclient.so"); - libname = strtok_r(libnames, " ", &p); - while (libname) { - libname = strtok_r(NULL, " ", &p); - if ((db_handle.lib = dlopen(libname, RTLD_LAZY | RTLD_LOCAL)) != NULL) break; - } - free(libnames); - if (!db_handle.lib) return ERR(*ctx, ENOENT, "can't load libmysqlclient library (%s), tried: ", dlerror(), MYSQL_LIBPATH " libmysqlclient.so"); + db_handle.lib = dlopen(MYSQL_SONAME, RTLD_LAZY | RTLD_LOCAL); + if (!db_handle.lib) return ERR(*ctx, ENOENT, "dlopen(): " MYSQL_SONAME ": %s", dlerror()); do { LOAD(mysql_init, "mysql_init"); LOAD(mysql_get_client_version, "mysql_get_client_version"); @@ -236,8 +230,8 @@ int glite_lbu_InitDBContext(glite_lbu_DBContext *ctx) { // check the runtime version ver_u = db_handle.mysql_get_client_version(); if (ver_u != MYSQL_VERSION_ID) { - err = ERR(*ctx, EINVAL, "version mismatch (compiled '%lu', runtime '%lu')", MYSQL_VERSION_ID, ver_u); - break; + fprintf(stderr,"Warning: MySQL library version mismatch (compiled '%lu', runtime '%lu')", MYSQL_VERSION_ID, ver_u); + syslog(LOG_WARNING,"MySQL library version mismatch (compiled '%lu', runtime '%lu')", MYSQL_VERSION_ID, ver_u); } pthread_mutex_unlock(&db_handle.lock); @@ -904,7 +898,7 @@ static int lbu_err(glite_lbu_DBContext ctx, int code, const char *func, int line va_end(ap); } else ctx->err.desc = NULL; - dprintf(ctx, "[db %d] %s:%d %s\n", getpid(), func, line, desc); + dprintf(ctx, "[db %d] %s:%d %s\n", getpid(), func, line, desc ? ctx->err.desc : ""); return code; } else return ctx->err.code; -- 1.8.2.3