diff options
author | unknown <monty@hundin.mysql.fi> | 2002-05-16 16:32:51 +0300 |
---|---|---|
committer | unknown <monty@hundin.mysql.fi> | 2002-05-16 16:32:51 +0300 |
commit | d2b95cd7ab5b3ed450af572e9c77cd11d3c420ba (patch) | |
tree | 145820cb9685468167f09ba07a59a1f61ca640cf /mysys | |
parent | eba5ec8b4bceabab302462db850882f715a7b040 (diff) | |
download | mariadb-git-d2b95cd7ab5b3ed450af572e9c77cd11d3c420ba.tar.gz |
New my_gethostbyname_r() handling
Changed some status variable names
Fix bug in GRANT ... PASSWORD string
Docs/manual.texi:
Update of variable names
include/my_net.h:
New my_gethostbyname_r() handling
include/my_pthread.h:
New my_gethostbyname_r() handling
libmysql/Makefile.shared:
New my_gethostbyname_r() handling
libmysql/libmysql.c:
New my_gethostbyname_r() handling
mysys/Makefile.am:
New my_gethostbyname_r() handling
mysys/my_pthread.c:
New my_gethostbyname_r() handling
mysys/my_thr_init.c:
New my_gethostbyname_r() handling
sql/hostname.cc:
New my_gethostbyname_r() handling
sql/mini_client.cc:
New my_gethostbyname_r() handling
sql/mysqld.cc:
change some status variable names
sql/sql_acl.cc:
Fix bug in GRANT ... PASSWORD string
Diffstat (limited to 'mysys')
-rw-r--r-- | mysys/Makefile.am | 2 | ||||
-rw-r--r-- | mysys/my_gethostbyname.c | 119 | ||||
-rw-r--r-- | mysys/my_pthread.c | 54 | ||||
-rw-r--r-- | mysys/my_thr_init.c | 9 |
4 files changed, 129 insertions, 55 deletions
diff --git a/mysys/Makefile.am b/mysys/Makefile.am index 73cd9768013..ce24d6f6f5b 100644 --- a/mysys/Makefile.am +++ b/mysys/Makefile.am @@ -46,7 +46,7 @@ libmysys_a_SOURCES = my_init.c my_getwd.c mf_getdate.c\ my_quick.c my_lockmem.c my_static.c \ getopt.c getopt1.c getvar.c my_mkdir.c \ default.c my_compress.c checksum.c raid.cc my_net.c \ - my_vsnprintf.c charset.c my_bitmap.c + my_vsnprintf.c charset.c my_bitmap.c my_gethostbyname.c EXTRA_DIST = thr_alarm.c thr_lock.c my_pthread.c my_thr_init.c \ thr_mutex.c thr_rwlock.c libmysys_a_LIBADD = @THREAD_LOBJECTS@ diff --git a/mysys/my_gethostbyname.c b/mysys/my_gethostbyname.c new file mode 100644 index 00000000000..19381734e83 --- /dev/null +++ b/mysys/my_gethostbyname.c @@ -0,0 +1,119 @@ +/* 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 "my_pthread.h" +#include <assert.h> +#include <my_net.h> +#if !defined(MSDOS) && !defined(__WIN__) +#include <netdb.h> +#endif + +/* This file is not needed if my_gethostbyname_r is a macro */ +#if !defined(my_gethostbyname_r) + +#ifndef THREAD +#define pthread_mutex_lock(A) +#define pthread_mutex_unlock(A) +#endif + +/* + 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 */ diff --git a/mysys/my_pthread.c b/mysys/my_pthread.c index 72409b6aa86..706712086c6 100644 --- a/mysys/my_pthread.c +++ b/mysys/my_pthread.c @@ -23,9 +23,6 @@ #include <m_string.h> #include <thr_alarm.h> #include <assert.h> -#if !defined(MSDOS) && !defined(__WIN__) -#include <netdb.h> -#endif #if (defined(__BSD__) || defined(_BSDI_VERSION)) && !defined(HAVE_mit_thread) #define SCHED_POLICY SCHED_RR @@ -424,57 +421,6 @@ int my_pthread_cond_timedwait(pthread_cond_t *cond, } #endif /* HAVE_BROKEN_PTHREAD_COND_TIMEDWAIT */ -/* - Emulate SOLARIS style calls, not because it's better, but just to make the - usage of getbostbyname_r simpler. -*/ - -#if !defined(my_gethostbyname_r) && 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 - -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 */ -#endif - /* Some help functions */ diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c index e1f9e23912e..2782576d8cd 100644 --- a/mysys/my_thr_init.c +++ b/mysys/my_thr_init.c @@ -35,6 +35,9 @@ pthread_mutex_t THR_LOCK_malloc,THR_LOCK_open,THR_LOCK_keycache, #ifndef HAVE_LOCALTIME_R pthread_mutex_t LOCK_localtime_r; #endif +#ifndef HAVE_GETHOSTBYNAME_R +pthread_mutex_t LOCK_gethostbyname_r; +#endif #ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP pthread_mutexattr_t my_fast_mutexattr; #endif @@ -78,6 +81,9 @@ my_bool my_thread_global_init(void) #ifndef HAVE_LOCALTIME_R 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 return my_thread_init(); } @@ -92,6 +98,9 @@ void my_thread_global_end(void) #ifdef PPTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP pthread_mutexattr_destroy(&my_errchk_mutexattr); #endif +#ifndef HAVE_GETHOSTBYNAME_R + pthread_mutex_destroy(&LOCK_gethostbyname_r); +#endif } static long thread_id=0; |