1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-08 14:02:17 +03:00

Fixes for Solaris build (Bugs CONC-36,37 and 38)

This commit is contained in:
holzboote@googlemail.com
2013-07-22 07:22:04 +02:00
parent d6f3bb4c9f
commit ab2403287d
13 changed files with 71 additions and 192 deletions

View File

@@ -81,8 +81,32 @@ SET(SHAREDIR "share")
SET(DEFAULT_CHARSET_HOME "${CMAKE_INSTALL_PREFIX}") SET(DEFAULT_CHARSET_HOME "${CMAKE_INSTALL_PREFIX}")
SET(PLUGINDIR "${CMAKE_INSTALL_PREFIX}/lib/plugin") SET(PLUGINDIR "${CMAKE_INSTALL_PREFIX}/lib/plugin")
#Check for threads INCLUDE(cmake/SearchLibrary.cmake)
FIND_PACKAGE(Threads)
IF(WITH_EXTERNAL_ZLIB)
FIND_PACKAGE(ZLIB QUIET)
IF(${ZLIB_FOUND})
SET(LIBZ "-lz")
ENDIF()
ENDIF()
IF(UNIX)
SEARCH_LIBRARY(LIBNSL inet_ntoa "nsl_r;nsl")
SEARCH_LIBRARY(LIBBIND bind "bind;socket")
SEARCH_LIBRARY(LIBSOCKET setsockopt "socket")
SEARCH_LIBRARY(LIBDL dlopen "dl")
SEARCH_LIBRARY(LIBM floor m)
SET(EXTRA_LIBS "${LIBNSL}" "${LIBBIND}" "${LIBSOCKET}" "${LIBDL}" "${LIBM}" "${LIBZ}")
FIND_PACKAGE(Threads)
SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${LIBNSL} ${LIBBIND}
${LIBSOCKET} ${LIBDL} ${LIBM} ${CMAKE_THREAD_LIBS_INIT})
#remove possible dups from required libraries
LIST(LENGTH CMAKE_REQUIRED_LIBRARIES rllength)
IF(${rllength} GREATER 0)
LIST(REMOVE_DUPLICATES CMAKE_REQUIRED_LIBRARIES)
ENDIF()
ENDIF()
IF(CMAKE_HAVE_PTHREAD_H) IF(CMAKE_HAVE_PTHREAD_H)
SET(CMAKE_REQUIRED_INCLUDES pthread.h) SET(CMAKE_REQUIRED_INCLUDES pthread.h)
@@ -97,14 +121,6 @@ ELSEIF()
SET(HAVE_THREADS ${CMAKE_USE_PTHREADS}) SET(HAVE_THREADS ${CMAKE_USE_PTHREADS})
ENDIF() ENDIF()
IF(UNIX)
FIND_LIBRARY(DL_LIBRARY dl)
IF(DL_LIBRARY)
SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${CMAKE_DL_LIBS})
ENDIF()
FIND_LIBRARY(MATH_LIBRARY m)
ENDIF()
# check for various include files # check for various include files
INCLUDE(${CMAKE_SOURCE_DIR}/cmake/CheckIncludeFiles.cmake) INCLUDE(${CMAKE_SOURCE_DIR}/cmake/CheckIncludeFiles.cmake)
# check for various functions # check for various functions
@@ -120,10 +136,6 @@ IF(WITH_SSL)
ENDIF() ENDIF()
ENDIF() ENDIF()
IF(WITH_EXTERNAL_ZLIB)
FIND_PACKAGE(ZLIB QUIET)
ENDIF()
IF(WITH_SQLITE) IF(WITH_SQLITE)
ADD_DEFINITIONS(-DHAVE_SQLITE) ADD_DEFINITIONS(-DHAVE_SQLITE)
ENDIF() ENDIF()

View File

@@ -92,7 +92,7 @@ ELSE(WIN32)
IF (NOT SOCKET_SIZE_TYPE) IF (NOT SOCKET_SIZE_TYPE)
CHECK_C_SOURCE_COMPILES(" CHECK_C_SOURCE_COMPILES("
#include <sys/socket.h> #include <sys/socket.h>
int main() int main(int argc, char **argv)
{ {
getsockname(0, 0, (${CHECK_TYPE} *)0); getsockname(0, 0, (${CHECK_TYPE} *)0);
return 0; return 0;

23
cmake/SearchLibrary.cmake Normal file
View File

@@ -0,0 +1,23 @@
INCLUDE(CheckFunctionExists)
INCLUDE(CheckLibraryExists)
FUNCTION(SEARCH_LIBRARY library_name function liblist)
IF(${${library_name}})
RETURN()
ENDIF()
CHECK_FUNCTION_EXISTS(${function} HAVE_${function}_IN_LIBC)
# check if function is part of libc
IF(HAVE_${function}_IN_LIBC)
SET(${library_name} "" PARENT_SCOPE)
RETURN()
ENDIF()
FOREACH(lib ${liblist})
CHECK_LIBRARY_EXISTS(${lib} ${function} "" HAVE_${function}_IN_${lib})
IF(HAVE_${function}_IN_${lib})
SET(${library_name} ${lib} PARENT_SCOPE)
SET(HAVE_${library_name} 1 PARENT_SCOPE)
RETURN()
ENDIF()
ENDFOREACH()
ENDFUNCTION()

View File

@@ -1,6 +1,4 @@
#define HAVE_GETHOSTBYNAME_R_GLIBC2_STYLE 1
/* /*
* Include file constants (processed in LibmysqlIncludeFiles.txt 1 * Include file constants (processed in LibmysqlIncludeFiles.txt 1
*/ */

View File

@@ -34,38 +34,6 @@ extern "C" {
#endif #endif
#endif /* !defined(MSDOS) && !defined(_WIN32) */ #endif /* !defined(MSDOS) && !defined(_WIN32) */
/*
Handling of gethostbyname_r()
*/
#if !defined(HPUX)
struct hostent;
#endif /* HPUX */
#if !defined(HAVE_GETHOSTBYNAME_R)
struct hostent *my_gethostbyname_r(const char *name,
struct hostent *result, char *buffer,
int buflen, int *h_errnop);
void my_gethostbyname_r_free(void);
#elif defined(HAVE_PTHREAD_ATTR_CREATE) || defined(_AIX) || defined(HAVE_GETHOSTBYNAME_R_GLIBC2_STYLE)
#define my_gethostbyname_r_free()
#if !defined(HAVE_GETHOSTBYNAME_R_GLIBC2_STYLE) && !defined(HPUX)
#define GETHOSTBYNAME_BUFF_SIZE sizeof(struct hostent_data)
#endif /* !defined(HAVE_GETHOSTBYNAME_R_GLIBC2_STYLE) */
#elif defined(HAVE_GETHOSTBYNAME_R_RETURN_INT)
#define GETHOSTBYNAME_BUFF_SIZE sizeof(struct hostent_data)
struct hostent *my_gethostbyname_r(const char *name,
struct hostent *result, char *buffer,
int buflen, int *h_errnop);
#define my_gethostbyname_r_free()
#else
#define my_gethostbyname_r(A,B,C,D,E) gethostbyname_r((A),(B),(C),(D),(E))
#define my_gethostbyname_r_free()
#endif /* !defined(HAVE_GETHOSTBYNAME_R) */
#ifndef GETHOSTBYNAME_BUFF_SIZE
#define GETHOSTBYNAME_BUFF_SIZE 2048
#endif
/* On SCO you get a link error when refering to h_errno */ /* On SCO you get a link error when refering to h_errno */
#ifdef SCO #ifdef SCO

View File

@@ -56,7 +56,6 @@ my_div.c
my_error.c my_error.c
my_fopen.c my_fopen.c
my_fstream.c my_fstream.c
my_gethostbyname.c
my_getwd.c my_getwd.c
my_init.c my_init.c
my_lib.c my_lib.c

View File

@@ -364,7 +364,7 @@ mysql_load_plugin_v(MYSQL *mysql, const char *name, int type,
name, SO_EXT, NullS); name, SO_EXT, NullS);
/* Open new dll handle */ /* Open new dll handle */
if (!(dlhandle= dlopen(dlpath, RTLD_NOW))) if (!(dlhandle= dlopen((const char *)dlpath, RTLD_NOW)))
{ {
#ifdef _WIN32 #ifdef _WIN32
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,

View File

@@ -317,9 +317,6 @@ static int DoTrace(CODE_STATE *cs);
/* Test to see if file is writable */ /* Test to see if file is writable */
#if defined(HAVE_ACCESS) #if defined(HAVE_ACCESS)
static BOOLEAN Writable(const char *pathname); static BOOLEAN Writable(const char *pathname);
/* Change file owner and group */
static void ChangeOwner(CODE_STATE *cs, char *pathname);
/* Allocate memory for runtime support */
#endif #endif
static void DoPrefix(CODE_STATE *cs, uint line); static void DoPrefix(CODE_STATE *cs, uint line);

View File

@@ -1406,7 +1406,7 @@ mysql_connect(MYSQL *mysql,const char *host,
*/ */
MYSQL * STDCALL MYSQL * STDCALL
mysql_real_connect(MYSQL *mysql,const char *host, const char *user, mysql_real_connect(MYSQL *mysql, const char *host, const char *user,
const char *passwd, const char *db, const char *passwd, const char *db,
uint port, const char *unix_socket,unsigned long client_flag) uint port, const char *unix_socket,unsigned long client_flag)
{ {
@@ -1417,16 +1417,16 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
db, port, unix_socket, client_flag); db, port, unix_socket, client_flag);
} }
MYSQL *mthd_my_real_connect(MYSQL *mysql,const char *host, const char *user, MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user,
const char *passwd, const char *db, const char *passwd, const char *db,
uint port, const char *unix_socket,unsigned long client_flag) uint port, const char *unix_socket, unsigned long client_flag)
{ {
char buff[NAME_LEN+USERNAME_LENGTH+100]; char buff[NAME_LEN+USERNAME_LENGTH+100];
char *end, *end_pkt, *host_info, char *end, *end_pkt, *host_info,
*charset_name= NULL; *charset_name= NULL;
my_socket sock; my_socket sock;
char *scramble_data; char *scramble_data;
const char * scramble_plugin; const char *scramble_plugin;
uint pkt_length, scramble_len, pkt_scramble_len= 0; uint pkt_length, scramble_len, pkt_scramble_len= 0;
NET *net= &mysql->net; NET *net= &mysql->net;
#ifdef _WIN32 #ifdef _WIN32
@@ -1625,10 +1625,12 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql,const char *host, const char *user,
goto error; goto error;
} }
/* last call to connect 2 failed */
if (rc) if (rc)
{ {
my_set_error(mysql, CR_CONN_HOST_ERROR, SQLSTATE_UNKNOWN, ER(CR_CONN_HOST_ERROR), my_set_error(mysql, CR_CONN_HOST_ERROR, SQLSTATE_UNKNOWN, ER(CR_CONN_HOST_ERROR),
host, rc); host, rc);
closesocket(sock);
goto error; goto error;
} }
} }

View File

@@ -1,113 +0,0 @@
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA */
/* Thread safe version of gethostbyname_r() */
#include "mysys_priv.h"
#include <assert.h>
#if !defined(MSDOS) && !defined(_WIN32)
#include <netdb.h>
#endif
#include <my_net.h>
/* This file is not needed if my_gethostbyname_r is a macro */
#if !defined(my_gethostbyname_r)
/*
Emulate SOLARIS style calls, not because it's better, but just to make the
usage of getbostbyname_r simpler.
*/
#if defined(HAVE_GETHOSTBYNAME_R)
#if defined(HAVE_GETHOSTBYNAME_R_GLIBC2_STYLE)
struct hostent *my_gethostbyname_r(const char *name,
struct hostent *result, char *buffer,
int buflen, int *h_errnop)
{
struct hostent *hp;
dbug_assert((size_t) buflen >= sizeof(*result));
if (gethostbyname_r(name,result, buffer, (size_t) buflen, &hp, h_errnop))
return 0;
return hp;
}
#elif defined(HAVE_GETHOSTBYNAME_R_RETURN_INT)
struct hostent *my_gethostbyname_r(const char *name,
struct hostent *result, char *buffer,
int buflen, int *h_errnop)
{
dbug_assert(buflen >= sizeof(struct hostent_data));
if (gethostbyname_r(name,result,(struct hostent_data *) buffer) == -1)
{
*h_errnop= errno;
return 0;
}
return result;
}
#else
/* gethostbyname_r with similar interface as gethostbyname() */
struct hostent *my_gethostbyname_r(const char *name,
struct hostent *result, char *buffer,
int buflen, int *h_errnop)
{
struct hostent *hp;
dbug_assert(buflen >= sizeof(struct hostent_data));
hp= gethostbyname_r(name,result,(struct hostent_data *) buffer);
*h_errnop= errno;
return hp;
}
#endif /* GLIBC2_STYLE_GETHOSTBYNAME_R */
#else /* !HAVE_GETHOSTBYNAME_R */
#ifdef THREAD
extern pthread_mutex_t LOCK_gethostbyname_r;
#endif
/*
No gethostbyname_r() function exists.
In this case we have to keep a mutex over the call to ensure that no
other thread is going to reuse the internal memory.
The user is responsible to call my_gethostbyname_r_free() when he
is finished with the structure.
*/
struct hostent *my_gethostbyname_r(const char *name,
struct hostent *result, char *buffer,
int buflen, int *h_errnop)
{
struct hostent *hp;
pthread_mutex_lock(&LOCK_gethostbyname_r);
hp= gethostbyname(name);
*h_errnop= h_errno;
return hp;
}
void my_gethostbyname_r_free()
{
pthread_mutex_unlock(&LOCK_gethostbyname_r);
}
#endif /* !HAVE_GETHOSTBYNAME_R */
#endif /* !my_gethostbyname_r */

View File

@@ -38,9 +38,6 @@ pthread_mutex_t LOCK_ssl_config;
#ifndef HAVE_LOCALTIME_R #ifndef HAVE_LOCALTIME_R
pthread_mutex_t LOCK_localtime_r; pthread_mutex_t LOCK_localtime_r;
#endif #endif
#ifndef HAVE_GETHOSTBYNAME_R
pthread_mutex_t LOCK_gethostbyname_r;
#endif
#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP #ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
pthread_mutexattr_t my_fast_mutexattr; pthread_mutexattr_t my_fast_mutexattr;
#endif #endif
@@ -82,9 +79,6 @@ my_bool my_thread_global_init(void)
#endif #endif
#ifndef HAVE_LOCALTIME_R #ifndef HAVE_LOCALTIME_R
pthread_mutex_init(&LOCK_localtime_r,MY_MUTEX_INIT_SLOW); pthread_mutex_init(&LOCK_localtime_r,MY_MUTEX_INIT_SLOW);
#endif
#ifndef HAVE_GETHOSTBYNAME_R
pthread_mutex_init(&LOCK_gethostbyname_r,MY_MUTEX_INIT_SLOW);
#endif #endif
return my_thread_init(); return my_thread_init();
} }
@@ -103,9 +97,6 @@ void my_thread_global_end(void)
#ifdef HAVE_OPENSSL #ifdef HAVE_OPENSSL
pthread_mutex_destroy(&LOCK_ssl_config); pthread_mutex_destroy(&LOCK_ssl_config);
#endif #endif
#ifndef HAVE_GETHOSTBYNAME_R
pthread_mutex_destroy(&LOCK_gethostbyname_r);
#endif
} }
static long thread_id=0; static long thread_id=0;
@@ -240,7 +231,7 @@ extern void **my_thread_var_dbug()
if (! THR_KEY_mysys_initialized) if (! THR_KEY_mysys_initialized)
return NULL; return NULL;
tmp= _my_thread_var(); tmp= _my_thread_var();
return tmp && tmp->initialized ? &tmp->dbug : 0; return tmp && tmp->initialized ? (void **)&tmp->dbug : 0;
} }
#endif /* DBUG_OFF */ #endif /* DBUG_OFF */

View File

@@ -12,13 +12,15 @@ ENDFOREACH(dep)
IF(UNIX) IF(UNIX)
IF(OPENSSL_LIBRARIES) IF(OPENSSL_LIBRARIES)
SET(extra_dynamic_LDFLAGS "${extra_dynamic_LDFLAGS} -lssl") SET(extra_dynamic_LDFLAGS "${extra_dynamic_LDFLAGS} -lssl")
ENDIF(OPENSSL_LIBRARIES) ENDIF()
IF(DL_LIBRARY) SEARCH_LIBRARY(LIBNSL getaddrinfo "nsl_r;nsl")
SET(extra_dynamic_LDFLAGS "${extra_dynamic_LDFLAGS} -ldl") SEARCH_LIBRARY(LIBBIND bind "bind;socket")
ENDIF(DL_LIBRARY) SEARCH_LIBRARY(LIBSOCKET setsockopt "socket")
IF(MATH_LIBRARY) SEARCH_LIBRARY(LIBDL dlopen "dl")
SET(extra_dynamic_LDFLAGS "${extra_dynamic_LDFLAGS} -lm") SEARCH_LIBRARY(LIBM floor m)
ENDIF(MATH_LIBRARY) FOREACH(lib ${EXTRA_LIBS})
SET(extra_dynamic_LDFLAGS "${extra_dynamic_LDFLAGS} -l${lib}")
ENDFOREACH()
IF(WITH_SQLITE) IF(WITH_SQLITE)
SET(extra_dynamic_LDFLAGS "${extra_dynamic_LDFLAGS} -lsqlite") SET(extra_dynamic_LDFLAGS "${extra_dynamic_LDFLAGS} -lsqlite")
ENDIF() ENDIF()

View File

@@ -25,7 +25,7 @@ SET(API_TESTS "basic-t" "fetch" "charset" "logs" "cursor" "errors" "view" "ps" "
FOREACH(API_TEST ${API_TESTS}) FOREACH(API_TEST ${API_TESTS})
ADD_EXECUTABLE(${API_TEST} ${API_TEST}.c) ADD_EXECUTABLE(${API_TEST} ${API_TEST}.c)
TARGET_LINK_LIBRARIES(${API_TEST} mytap mariadbclient) TARGET_LINK_LIBRARIES(${API_TEST} mytap mariadbclient ${EXTRA_LIBS})
ADD_TEST(${API_TEST} ${EXECUTABLE_OUTPUT_PATH}/${API_TEST}) ADD_TEST(${API_TEST} ${EXECUTABLE_OUTPUT_PATH}/${API_TEST})
SET_TESTS_PROPERTIES(${API_TEST} PROPERTIES TIMEOUT 120) SET_TESTS_PROPERTIES(${API_TEST} PROPERTIES TIMEOUT 120)
ENDFOREACH(API_TEST) ENDFOREACH(API_TEST)