Commit 353fb57b authored by monty@hundin.mysql.fi's avatar monty@hundin.mysql.fi

New my_gethostbyname_r() handling

Changed some status variable names
Fix bug in GRANT ... PASSWORD string
parent 14b55bcc
......@@ -19678,17 +19678,17 @@ have.
@item @code{Open_files} @tab Number of files that are open.
@item @code{Open_streams} @tab Number of streams that are open (used mainly for logging).
@item @code{Opened_tables} @tab Number of tables that have been opened.
@item @code{Select_full_join} @tab Number of joins without keys (Should be 0).
@item @code{Select_full_join} @tab Number of joins without keys (If this is 0, you should carefully check the index of your tables).
@item @code{Select_full_range_join} @tab Number of joins where we used a range search on reference table.
@item @code{Select_range} @tab Number of joins where we used ranges on the first table. (It's normally not critical even if this is big.)
@item @code{Select_scan} @tab Number of joins where we scanned the first table.
@item @code{Select_range_check} @tab Number of joins without keys where we check for key usage after each row (Should be 0).
@item @code{Select_scan} @tab Number of joins where we did a full scann of the first table.
@item @code{Select_range_check} @tab Number of joins without keys where we check for key usage after each row (If this is 0, you should carefully check the index of your tables).
@item @code{Questions} @tab Number of queries sent to the server.
@item @code{Slave_open_temp_tables} @tab Number of temporary tables currently
open by the slave thread
@item @code{Slow_launch_threads} @tab Number of threads that have taken more than @code{slow_launch_time} to connect.
@item @code{Slow_launch_threads} @tab Number of threads that have taken more than @code{slow_launch_time} to create.
@item @code{Slow_queries} @tab Number of queries that have taken more than @code{long_query_time}. @xref{Slow query log}.
@item @code{Sort_merge_passes} @tab Number of merges the sort has to do. If this value is large you should consider increasing @code{sort_buffer}.
@item @code{Sort_merge_passes} @tab Number of merges passes the sort algoritm have had to do. If this value is large you should consider increasing @code{sort_buffer}.
@item @code{Sort_range} @tab Number of sorts that where done with ranges.
@item @code{Sort_rows} @tab Number of sorted rows.
@item @code{Sort_scan} @tab Number of sorts that where done by scanning the table.
......@@ -19712,8 +19712,8 @@ Some comments about the above:
If @code{Opened_tables} is big, then your @code{table_cache}
variable is probably too small.
@item
If @code{key_reads} is big, then your @code{key_cache} is probably too
small. The cache hit rate can be calculated with
If @code{key_reads} is big, then your @code{key_buffer_size} variable is
probably too small. The cache hit rate can be calculated with
@code{key_reads}/@code{key_read_requests}.
@item
If @code{Handler_read_rnd} is big, then you probably have a lot of
......@@ -46916,6 +46916,15 @@ not yet 100% confident in this code.
@appendixsubsec Changes in release 3.23.51
@itemize @bullet
@item
Changed name of variables @code{Com_show_master_stat} to
@code{Com_show_master_status} and @code{Com_show_slave_stat} to
@code{Com_show_slave_status}.
@item
Changed handling of @code{gethostbyname()} to make the client library
threadsafe even if @code{gethostbyname_r} doesn't exists.
@item
Fixed core-dump problem when giving a wrong password string to @code{GRANT}.
@item
Fixed bug in @code{DROP DATABASE} with symlinked directory.
@item
Fixed optimization problem with @code{DATETIME} and value outside
......@@ -36,6 +36,42 @@ extern "C" {
void my_inet_ntoa(struct in_addr in, char *buf);
/*
Handling of gethostbyname_r()
*/
#if defined(HAVE_PTHREAD_ATTR_CREATE) || defined(_AIX) || defined(HAVE_GETHOSTBYNAME_R_GLIBC2_STYLE)
#if !defined(HPUX)
struct hostent;
#endif /* HPUX */
struct hostent *my_gethostbyname_r(const char *name,
struct hostent *result, char *buffer,
int buflen, int *h_errnop);
#define my_gethostbyname_r_free()
#if defined(HAVE_GETHOSTBYNAME_R_GLIBC2_STYLE)
#define GETHOSTBYNAME_BUFF_SIZE 2048
#else
#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()
#elif !defined(HAVE_GETHOSTBYNAME_R)
#define GETHOSTBYNAME_BUFF_SIZE 2048
struct hostent *my_gethostbyname_r(const char *name,
struct hostent *result, char *buffer,
int buflen, int *h_errnop);
void my_gethostbyname_r_free();
#else
#define GETHOSTBYNAME_BUFF_SIZE 2048
#define my_gethostbyname_r(A,B,C,D,E) gethostbyname_r((A),(B),(C),(D),(E))
#define my_gethostbyname_r_free()
#endif /* defined(HAVE_PTHREAD_ATTR_CREATE) || defined(_AIX) || defined(HAVE_GETHOSTBYNAME_R_GLIBC2_STYLE) */
#ifdef __cplusplus
}
#endif
......@@ -426,31 +426,6 @@ struct tm *localtime_r(const time_t *clock, struct tm *res);
#define HAVE_PTHREAD_KILL
#endif
#if defined(HAVE_PTHREAD_ATTR_CREATE) || defined(_AIX) || defined(HAVE_GETHOSTBYNAME_R_GLIBC2_STYLE)
#if !defined(HPUX)
struct hostent;
#endif /* HPUX */
struct hostent *my_gethostbyname_r(const char *name,
struct hostent *result, char *buffer,
int buflen, int *h_errnop);
#if defined(HAVE_GETHOSTBYNAME_R_GLIBC2_STYLE)
#define GETHOSTBYNAME_BUFF_SIZE 2048
#else
#define GETHOSTBYNAME_BUFF_SIZE sizeof(struct hostent_data)
#endif /* defined(HAVE_GETHOSTBYNAME_R_GLIBC2_STYLE) */
#else
#ifdef 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);
#else
#define GETHOSTBYNAME_BUFF_SIZE 2048
#define my_gethostbyname_r(A,B,C,D,E) gethostbyname_r((A),(B),(C),(D),(E))
#endif /* HAVE_GETHOSTBYNAME_R_RETURN_INT */
#endif /* defined(HAVE_PTHREAD_ATTR_CREATE) || defined(_AIX) || defined(HAVE_GETHOSTBYNAME_R_GLIBC2_STYLE) */
#endif /* defined(__WIN__) */
/* safe_mutex adds checking to mutex for easier debugging */
......
......@@ -56,7 +56,7 @@ mysysobjects1 = my_init.lo my_static.lo my_malloc.lo my_realloc.lo \
thr_mutex.lo mulalloc.lo string.lo default.lo \
my_compress.lo array.lo my_once.lo list.lo my_net.lo \
charset.lo hash.lo mf_iocache.lo my_seek.lo \
my_pread.lo mf_cache.lo
my_pread.lo mf_cache.lo my_gethostbyname.lo
# Not needed in the minimum library
mysysobjects2 = getopt.lo getopt1.lo getvar.lo my_lib.lo
mysysobjects = $(mysysobjects1) $(mysysobjects2)
......
......@@ -1312,7 +1312,6 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
memcpy_fixed(&sock_addr.sin_addr,&ip_addr,sizeof(ip_addr));
}
else
#if defined(HAVE_GETHOSTBYNAME_R) && defined(_REENTRANT) && defined(THREAD)
{
int tmp_errno;
struct hostent tmp_hostent,*hp;
......@@ -1323,22 +1322,12 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
{
net->last_errno=CR_UNKNOWN_HOST;
sprintf(net->last_error, ER(CR_UNKNOWN_HOST), host, tmp_errno);
my_gethostbyname_r_free();
goto error;
}
memcpy(&sock_addr.sin_addr,hp->h_addr, (size_t) hp->h_length);
my_gethostbyname_r_free();
}
#else
{
struct hostent *hp;
if (!(hp=gethostbyname(host)))
{
net->last_errno=CR_UNKNOWN_HOST;
sprintf(net->last_error, ER(CR_UNKNOWN_HOST), host, socket_errno);
goto error;
}
memcpy(&sock_addr.sin_addr,hp->h_addr, (size_t) hp->h_length);
}
#endif
sock_addr.sin_port = (ushort) htons((ushort) port);
if (connect2(sock,(struct sockaddr *) &sock_addr, sizeof(sock_addr),
mysql->options.connect_timeout) <0)
......
......@@ -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@
......
/* 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 */
......@@ -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 */
......
......@@ -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
......@@ -77,6 +80,9 @@ my_bool my_thread_global_init(void)
#endif
#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;
......
......@@ -171,17 +171,22 @@ my_string ip_to_hostname(struct in_addr *in, uint *errors)
{
DBUG_PRINT("error",("gethostbyname_r returned %d",tmp_errno));
add_wrong_ip(in);
my_gethostbyname_r_free();
DBUG_RETURN(0);
}
if (!hp->h_name[0])
{
DBUG_PRINT("error",("Got an empty hostname"));
add_wrong_ip(in);
my_gethostbyname_r_free();
DBUG_RETURN(0); // Don't allow empty hostnames
}
if (!(name=my_strdup(hp->h_name,MYF(0))))
{
my_gethostbyname_r_free();
DBUG_RETURN(0); // out of memory
}
my_gethostbyname_r_free();
#else
VOID(pthread_mutex_lock(&LOCK_hostname));
if (!(hp=gethostbyaddr((char*) in,sizeof(*in), AF_INET)))
......
......@@ -614,7 +614,6 @@ mc_mysql_connect(MYSQL *mysql,const char *host, const char *user,
memcpy_fixed(&sock_addr.sin_addr,&ip_addr,sizeof(ip_addr));
}
else
#if defined(HAVE_GETHOSTBYNAME_R) && defined(_REENTRANT) && defined(THREAD)
{
int tmp_errno;
struct hostent tmp_hostent,*hp;
......@@ -625,22 +624,12 @@ mc_mysql_connect(MYSQL *mysql,const char *host, const char *user,
{
net->last_errno=CR_UNKNOWN_HOST;
sprintf(net->last_error, ER(CR_UNKNOWN_HOST), host, tmp_errno);
my_gethostbyname_r_free();
goto error;
}
memcpy(&sock_addr.sin_addr,hp->h_addr, (size_t) hp->h_length);
my_gethostbyname_r_free();
}
#else
{
struct hostent *hp;
if (!(hp=gethostbyname(host)))
{
net->last_errno=CR_UNKNOWN_HOST;
sprintf(net->last_error, ER(CR_UNKNOWN_HOST), host, socket_errno);
goto error;
}
memcpy(&sock_addr.sin_addr,hp->h_addr, (size_t) hp->h_length);
}
#endif
sock_addr.sin_port = (ushort) htons((ushort) port);
if (mc_sock_connect(sock,(struct sockaddr *) &sock_addr, sizeof(sock_addr),
mysql->options.connect_timeout) <0)
......
......@@ -3149,10 +3149,10 @@ struct show_var_st status_vars[]= {
{"Com_show_grants", (char*) (com_stat+(uint) SQLCOM_SHOW_GRANTS),SHOW_LONG},
{"Com_show_keys", (char*) (com_stat+(uint) SQLCOM_SHOW_KEYS),SHOW_LONG},
{"Com_show_logs", (char*) (com_stat+(uint) SQLCOM_SHOW_LOGS),SHOW_LONG},
{"Com_show_master_stat", (char*) (com_stat+(uint) SQLCOM_SHOW_MASTER_STAT),SHOW_LONG},
{"Com_show_master_status", (char*) (com_stat+(uint) SQLCOM_SHOW_MASTER_STAT),SHOW_LONG},
{"Com_show_open_tables", (char*) (com_stat+(uint) SQLCOM_SHOW_OPEN_TABLES),SHOW_LONG},
{"Com_show_processlist", (char*) (com_stat+(uint) SQLCOM_SHOW_PROCESSLIST),SHOW_LONG},
{"Com_show_slave_stat", (char*) (com_stat+(uint) SQLCOM_SHOW_SLAVE_STAT),SHOW_LONG},
{"Com_show_slave_status", (char*) (com_stat+(uint) SQLCOM_SHOW_SLAVE_STAT),SHOW_LONG},
{"Com_show_status", (char*) (com_stat+(uint) SQLCOM_SHOW_STATUS),SHOW_LONG},
{"Com_show_tables", (char*) (com_stat+(uint) SQLCOM_SHOW_TABLES),SHOW_LONG},
{"Com_show_variables", (char*) (com_stat+(uint) SQLCOM_SHOW_VARIABLES),SHOW_LONG},
......
......@@ -983,12 +983,17 @@ static int replace_user_table(TABLE *table, const LEX_USER &combo,
char *password,empty_string[1];
DBUG_ENTER("replace_user_table");
if (combo.password.str && combo.password.str[0])
password=combo.password.str;
else
{
password=empty_string;
empty_string[0]=0;
if (combo.password.str && combo.password.str[0])
{
if (combo.password.length != HASH_PASSWORD_LENGTH)
{
my_error(ER_PASSWORD_NO_MATCH,MYF(0));
DBUG_RETURN(-1);
}
password=combo.password.str;
}
table->field[0]->store(combo.host.str,combo.host.length);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment