64-bit portability fixes in network I/O

use $MAX_TABLES mysqltest variable to make join test portable
make test now works with the manager on IA64 Linux
parent 2d3f96b4
......@@ -2158,12 +2158,15 @@ static void var_from_env(const char* name, const char* def_val)
static void init_var_hash()
{
VAR* v;
if (hash_init(&var_hash, 1024, 0, 0, get_var_key, var_free, MYF(0)))
die("Variable hash initialization failed");
var_from_env("MASTER_MYPORT", "9306");
var_from_env("SLAVE_MYPORT", "9307");
var_from_env("MYSQL_TEST_DIR", "/tmp");
var_from_env("BIG_TEST", opt_big_test ? "1" : "0");
v=var_init(0,"MAX_TABLES", 0, (sizeof(ulong) == 4) ? "31" : "63",0);
hash_insert(&var_hash, (byte*)v);
}
......
......@@ -905,7 +905,8 @@ unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields,
static MYSQL_DATA *read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields,
uint fields)
{
uint field,pkt_len;
uint field;
ulong pkt_len;
ulong len;
uchar *cp;
char *to;
......@@ -991,7 +992,7 @@ read_one_row(MYSQL *mysql,uint fields,MYSQL_ROW row, ulong *lengths)
ulong pkt_len,len;
uchar *pos,*prev_pos;
if ((pkt_len=(uint) net_safe_read(mysql)) == packet_error)
if ((pkt_len=net_safe_read(mysql)) == packet_error)
return -1;
if (pkt_len == 1 && mysql->net.read_pos[0] == 254)
return 1; /* End of data */
......@@ -1453,7 +1454,7 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
my_socket sock;
uint32 ip_addr;
struct sockaddr_in sock_addr;
uint pkt_length;
ulong pkt_length;
NET *net= &mysql->net;
#ifdef __WIN__
HANDLE hPipe=INVALID_HANDLE_VALUE;
......@@ -2135,7 +2136,7 @@ int STDCALL mysql_read_query_result(MYSQL *mysql)
uchar *pos;
ulong field_count;
MYSQL_DATA *fields;
uint length;
ulong length;
DBUG_ENTER("mysql_read_query_result");
/* read from the connection which we actually used, which
......
......@@ -674,8 +674,8 @@ start_master()
elif [ x$DO_GDB = x1 ]
then
$ECHO "set args $master_args" > $GDB_MASTER_INIT
manager_launch master $XTERM -display :0 -title "Master" -e gdb -x \
$GDB_MASTER_INIT $MYSQLD
manager_launch master $XTERM -display $DISPLAY \
-title "Master" -e gdb -x $GDB_MASTER_INIT $MYSQLD
else
manager_launch master $MYSQLD $master_args
fi
......
......@@ -89,7 +89,7 @@ a
1
2
select t1.a from t1 as t1 left join t1 as t2 using (a) left join t1 as t3 using (a) left join t1 as t4 using (a) left join t1 as t5 using (a) left join t1 as t6 using (a) left join t1 as t7 using (a) left join t1 as t8 using (a) left join t1 as t9 using (a) left join t1 as t10 using (a) left join t1 as t11 using (a) left join t1 as t12 using (a) left join t1 as t13 using (a) left join t1 as t14 using (a) left join t1 as t15 using (a) left join t1 as t16 using (a) left join t1 as t17 using (a) left join t1 as t18 using (a) left join t1 as t19 using (a) left join t1 as t20 using (a) left join t1 as t21 using (a) left join t1 as t22 using (a) left join t1 as t23 using (a) left join t1 as t24 using (a) left join t1 as t25 using (a) left join t1 as t26 using (a) left join t1 as t27 using (a) left join t1 as t28 using (a) left join t1 as t29 using (a) left join t1 as t30 using (a) left join t1 as t31 using (a) left join t1 as t32 using (a) left join t1 as t33 using (a) left join t1 as t34 using (a) left join t1 as t35 using (a) left join t1 as t36 using (a) left join t1 as t37 using (a) left join t1 as t38 using (a) left join t1 as t39 using (a) left join t1 as t40 using (a) left join t1 as t41 using (a) left join t1 as t42 using (a) left join t1 as t43 using (a) left join t1 as t44 using (a) left join t1 as t45 using (a) left join t1 as t46 using (a) left join t1 as t47 using (a) left join t1 as t48 using (a) left join t1 as t49 using (a) left join t1 as t50 using (a) left join t1 as t51 using (a) left join t1 as t52 using (a) left join t1 as t53 using (a) left join t1 as t54 using (a) left join t1 as t55 using (a) left join t1 as t56 using (a) left join t1 as t57 using (a) left join t1 as t58 using (a) left join t1 as t59 using (a) left join t1 as t60 using (a) left join t1 as t61 using (a) left join t1 as t62 using (a) left join t1 as t63 using (a) left join t1 as t64 using (a) left join t1 as t65 using (a);
Too many tables. MySQL can only use 31 tables in a join
Too many tables. MySQL can only use $MAX_TABLES tables in a join
drop table t1;
CREATE TABLE t1 (
a int(11) NOT NULL,
......
#
# This failed for lia Perminov
#
eval_result; # because MAX_TABLES is different on 64-bit system
drop table if exists t1,t2;
create table t1 (id int primary key);
create table t2 (id int);
......
......@@ -351,11 +351,11 @@ static int mc_sock_connect(my_socket s, const struct sockaddr *name,
** or packet is an error message
*****************************************************************************/
uint STDCALL
ulong STDCALL
mc_net_safe_read(MYSQL *mysql)
{
NET *net= &mysql->net;
uint len=0;
ulong len=0;
if (net->vio != 0)
len=my_net_read(net);
......@@ -514,7 +514,7 @@ mc_mysql_connect(MYSQL *mysql,const char *host, const char *user,
my_socket sock;
ulong ip_addr;
struct sockaddr_in sock_addr;
uint pkt_length;
ulong pkt_length;
NET *net= &mysql->net;
thr_alarm_t alarmed;
ALARM alarm_buff;
......@@ -921,8 +921,8 @@ void STDCALL mc_mysql_free_result(MYSQL_RES *result)
DBUG_PRINT("warning",("Not all rows in set were read; Ignoring rows"));
for (;;)
{
uint pkt_len;
if ((pkt_len=(uint) mc_net_safe_read(result->handle)) == packet_error)
ulong pkt_len;
if ((pkt_len=mc_net_safe_read(result->handle)) == packet_error)
break;
if (pkt_len == 1 && result->handle->net.read_pos[0] == 254)
break; /* End of data */
......@@ -999,7 +999,7 @@ int STDCALL mc_mysql_read_query_result(MYSQL *mysql)
uchar *pos;
ulong field_count;
MYSQL_DATA *fields;
uint length;
ulong length;
DBUG_ENTER("mc_mysql_read_query_result");
if ((length = mc_net_safe_read(mysql)) == packet_error)
......@@ -1174,7 +1174,8 @@ static my_ulonglong mc_net_field_length_ll(uchar **packet)
static MYSQL_DATA *mc_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields,
uint fields)
{
uint field,pkt_len;
uint field;
ulong pkt_len;
ulong len;
uchar *cp;
char *to;
......@@ -1183,7 +1184,7 @@ static MYSQL_DATA *mc_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields,
NET *net = &mysql->net;
DBUG_ENTER("mc_read_rows");
if ((pkt_len=(uint) mc_net_safe_read(mysql)) == packet_error)
if ((pkt_len=mc_net_safe_read(mysql)) == packet_error)
DBUG_RETURN(0);
if (!(result=(MYSQL_DATA*) my_malloc(sizeof(MYSQL_DATA),
MYF(MY_WME | MY_ZEROFILL))))
......@@ -1260,7 +1261,7 @@ static int mc_read_one_row(MYSQL *mysql,uint fields,MYSQL_ROW row,
ulong pkt_len,len;
uchar *pos,*prev_pos;
if ((pkt_len=(uint) mc_net_safe_read(mysql)) == packet_error)
if ((pkt_len=mc_net_safe_read(mysql)) == packet_error)
return -1;
if (pkt_len == 1 && mysql->net.read_pos[0] == 254)
return 1; /* End of data */
......
......@@ -35,7 +35,7 @@ mc_mysql_init(MYSQL *mysql);
void STDCALL
mc_mysql_debug(const char *debug);
uint STDCALL
ulong STDCALL
mc_net_safe_read(MYSQL *mysql);
char * STDCALL mc_mysql_error(MYSQL *mysql);
......
......@@ -335,7 +335,7 @@ static int init_intvar_from_file(int* var, IO_CACHE* f, int default_val)
static int create_table_from_dump(THD* thd, NET* net, const char* db,
const char* table_name)
{
uint packet_len = my_net_read(net); // read create table statement
ulong packet_len = my_net_read(net); // read create table statement
Vio* save_vio;
HA_CHECK_OPT check_opt;
TABLE_LIST tables;
......@@ -870,7 +870,7 @@ command");
static uint read_event(MYSQL* mysql, MASTER_INFO *mi)
{
uint len = packet_error;
ulong len = packet_error;
// for convinience lets think we start by
// being in the interrupted state :-)
int read_errno = EINTR;
......@@ -890,7 +890,7 @@ static uint read_event(MYSQL* mysql, MASTER_INFO *mi)
}
if (abort_loop || abort_slave)
return packet_error;
if (len == packet_error || (int) len < 1)
if (len == packet_error || (long) len < 1)
{
sql_print_error("Error reading packet from server: %s (read_errno %d,\
server_errno=%d)",
......
......@@ -291,9 +291,9 @@ static void die(const char* fmt,...);
static void print_time(FILE* fp);
static void clean_up();
static struct manager_cmd* lookup_cmd(char* s,int len);
static void client_msg(NET* net,int err_code,const char* fmt,...);
static void client_msg_pre(NET* net,int err_code,const char* fmt,...);
static void client_msg_raw(NET* net,int err_code,int pre,const char* fmt,
static int client_msg(NET* net,int err_code,const char* fmt,...);
static int client_msg_pre(NET* net,int err_code,const char* fmt,...);
static int client_msg_raw(NET* net,int err_code,int pre,const char* fmt,
va_list args);
static int authenticate(struct manager_thd* thd);
static char* read_line(struct manager_thd* thd); /* returns pointer to end of
......@@ -307,6 +307,27 @@ static int exec_line(struct manager_thd* thd,char* buf,char* buf_end);
void print_stacktrace();
#endif
static void log_msg(const char* fmt, int msg_type, va_list args);
/* No 'inline' here becasue functions with ... can't do that portable */
#define LOG_MSG_FUNC(type,TYPE) static void type \
(const char* fmt,...) { \
va_list args; \
va_start(args,fmt); \
log_msg(fmt,TYPE,args);\
}
LOG_MSG_FUNC(log_err,LOG_ERR)
LOG_MSG_FUNC(log_warn,LOG_WARN)
LOG_MSG_FUNC(log_info,LOG_INFO)
#ifndef DBUG_OFF
LOG_MSG_FUNC(log_debug,LOG_DEBUG)
#else
void log_debug(const char* __attribute__((unused)) fmt,...) {}
#endif
static void handle_segfault(int sig)
{
if (in_segfault)
......@@ -369,11 +390,13 @@ static int exec_line(struct manager_thd* thd,char* buf,char* buf_end)
struct manager_cmd* cmd;
for (;p<buf_end && !isspace(*p);p++)
*p=tolower(*p);
log_info("Command '%s'", buf);
if (!(cmd=lookup_cmd(buf,(int)(p-buf))))
{
client_msg(&thd->net,MANAGER_CLIENT_ERR,
"Unrecognized command, type help to see list of supported\
commands");
if(client_msg(&thd->net,MANAGER_CLIENT_ERR,
"Unrecognized command '%s', type help to see list of supported\
commands", buf))
thd->fatal=1;
return 1;
}
for (;p<buf_end && isspace(*p);p++);
......@@ -1025,24 +1048,6 @@ static void log_msg(const char* fmt, int msg_type, va_list args)
pthread_mutex_unlock(&lock_log);
}
/* No 'inline' here becasue functions with ... can't do that portable */
#define LOG_MSG_FUNC(type,TYPE) static void type \
(const char* fmt,...) { \
va_list args; \
va_start(args,fmt); \
log_msg(fmt,TYPE,args);\
}
LOG_MSG_FUNC(log_err,LOG_ERR)
LOG_MSG_FUNC(log_warn,LOG_WARN)
LOG_MSG_FUNC(log_info,LOG_INFO)
#ifndef DBUG_OFF
LOG_MSG_FUNC(log_debug,LOG_DEBUG)
#else
void log_debug(const char* __attribute__((unused)) fmt,...) {}
#endif
static pthread_handler_decl(process_launcher_messages,
__attribute__((unused)) arg)
{
......@@ -1121,7 +1126,7 @@ static pthread_handler_decl(process_connection,arg)
return 0; /* Don't get cc warning */
}
static void client_msg_raw(NET* net, int err_code, int pre, const char* fmt,
static int client_msg_raw(NET* net, int err_code, int pre, const char* fmt,
va_list args)
{
char buf[MAX_CLIENT_MSG_LEN],*p,*buf_end;
......@@ -1136,29 +1141,36 @@ static void client_msg_raw(NET* net, int err_code, int pre, const char* fmt,
p=buf_end - 2;
*p++='\r';
*p++='\n';
if (my_net_write(net,buf,(uint)(p-buf)) || net_flush(net))
log_err("Failed writing to client: errno=%d",net->last_errno);
{
p[-2]=0;
log_err("Failed writing '%s' to client: errno=%d",buf,errno);
net_end(net);
return 1;
}
return 0;
}
static void client_msg(NET* net, int err_code, const char* fmt, ...)
static int client_msg(NET* net, int err_code, const char* fmt, ...)
{
va_list args;
va_start(args,fmt);
client_msg_raw(net,err_code,0,fmt,args);
return client_msg_raw(net,err_code,0,fmt,args);
}
static void client_msg_pre(NET* net, int err_code, const char* fmt, ...)
static int client_msg_pre(NET* net, int err_code, const char* fmt, ...)
{
va_list args;
va_start(args,fmt);
client_msg_raw(net,err_code,1,fmt,args);
return client_msg_raw(net,err_code,1,fmt,args);
}
static char* read_line(struct manager_thd* thd)
{
uint len;
int len;
char* p, *buf_end;
if ((len=my_net_read(&thd->net)) == packet_error)
if ((len=my_net_read(&thd->net)) == (int)packet_error || !len)
{
log_err("Error reading command from client (Error: %d)",
errno);
......@@ -1212,6 +1224,12 @@ struct manager_thd* manager_thd_new(Vio* vio)
static void manager_thd_free(struct manager_thd* thd)
{
NET* net=&thd->net;
if (net->vio)
{
vio_delete(net->vio);
net->vio=0;
}
net_end(&thd->net);
}
......@@ -1379,15 +1397,18 @@ static int run_server_loop()
vio_close(vio);
continue;
}
if (authenticate(thd))
{
client_msg(&thd->net,MANAGER_ACCESS, "Access denied");
manager_thd_free(thd);
log_info("Client failed to authenticate");
continue;
}
if (shutdown_requested)
{
manager_thd_free(thd);
break;
}
if (one_thread)
{
process_connection((void*)thd);
......
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