Skip to content

Commit fb9bb62

Browse files
author
[email protected]/nosik.monty.fi
committed
Added some missing DBUG_RETURN
Fixed that --valgrind works again with mysql-test-run.sh Extended error messages when loosing connection during mysql_real_connect()
1 parent 306b871 commit fb9bb62

6 files changed

Lines changed: 83 additions & 15 deletions

File tree

client/mysqldump.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,7 +2203,7 @@ static void dump_table(char *table, char *db)
22032203
The "table" could be a view. If so, we don't do anything here.
22042204
*/
22052205
if (strcmp (table_type, "VIEW") == 0)
2206-
return;
2206+
DBUG_VOID_RETURN;
22072207

22082208
/* Check --no-data flag */
22092209
if (opt_no_data)
@@ -2869,7 +2869,7 @@ static int dump_all_tables_in_db(char *database)
28692869
*afterdot++= '.';
28702870

28712871
if (init_dumping(database, init_dumping_tables))
2872-
return 1;
2872+
DBUG_RETURN(1);
28732873
if (opt_xml)
28742874
print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NullS);
28752875
if (lock_tables)
@@ -2923,7 +2923,7 @@ static int dump_all_tables_in_db(char *database)
29232923
fprintf(md_result_file,"\n--\n-- Flush Grant Tables \n--\n");
29242924
fprintf(md_result_file,"\n/*! FLUSH PRIVILEGES */;\n");
29252925
}
2926-
return 0;
2926+
DBUG_RETURN(0);
29272927
} /* dump_all_tables_in_db */
29282928

29292929

include/errmsg.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ extern const char *client_errors[]; /* Error messages */
9797
#define CR_NO_STMT_METADATA 2052
9898
#define CR_NO_RESULT_SET 2053
9999
#define CR_NOT_IMPLEMENTED 2054
100-
#define CR_ERROR_LAST /*Copy last error nr:*/ 2054
100+
#define CR_SERVER_LOST_EXTENDED 2055
101+
#define CR_ERROR_LAST /*Copy last error nr:*/ 2055
101102
/* Add error numbers before CR_ERROR_LAST and change it accordingly. */
102103

libmysql/errmsg.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ const char *client_errors[]=
8282
"Prepared statement contains no metadata",
8383
"Attempt to read a row while there is no result set associated with the statement",
8484
"This feature is not implemented yet",
85+
"Lost connection to MySQL server at '%s', system error: %d",
8586
""
8687
};
8788

@@ -145,6 +146,7 @@ const char *client_errors[]=
145146
"Prepared statement contains no metadata",
146147
"Attempt to read a row while there is no result set associated with the statement",
147148
"This feature is not implemented yet",
149+
"Lost connection to MySQL server at '%s', system error: %d",
148150
""
149151
};
150152

@@ -206,6 +208,7 @@ const char *client_errors[]=
206208
"Prepared statement contains no metadata",
207209
"Attempt to read a row while there is no result set associated with the statement",
208210
"This feature is not implemented yet",
211+
"Lost connection to MySQL server at '%s', system error: %d",
209212
""
210213
};
211214
#endif

mysql-test/mysql-test-run.pl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,7 +2047,7 @@ ()
20472047
}
20482048

20492049
# Remove old log files
2050-
foreach my $name (glob("r/*.reject r/*.progress r/*.log r/*.warnings"))
2050+
foreach my $name (glob("r/*.progress r/*.log r/*.warnings"))
20512051
{
20522052
unlink($name);
20532053
}
@@ -2995,14 +2995,14 @@ ($)
29952995
{
29962996
my ($tinfo)= @_;
29972997

2998-
# Open mysqltest.log
2998+
# Open mysqltest-time
29992999
my $F= IO::File->new($path_timefile) or
30003000
mtr_error("can't open file \"$path_timefile\": $!");
30013001
my $reason;
30023002

30033003
while ( my $line= <$F> )
30043004
{
3005-
# Look for "reason: <reason fo skiping test>"
3005+
# Look for "reason: <reason for skipping test>"
30063006
if ( $line =~ /reason: (.*)/ )
30073007
{
30083008
$reason= $1;

mysql-test/mysql-test-run.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ find_valgrind()
123123
fi
124124
# >=2.1.2 requires the --tool option, some versions write to stdout, some to stderr
125125
valgrind --help 2>&1 | grep "\-\-tool" > /dev/null && FIND_VALGRIND="$FIND_VALGRIND --tool=memcheck"
126-
FIND_VALGRIND="$FIND_VALGRIND --alignment=8 --leak-check=yes --num-callers=16 --suppressions=$CWD/valgrind.supp"
126+
FIND_VALGRIND="$FIND_VALGRIND --alignment=8 --leak-check=yes --num-callers=16 --suppressions=$MYSQL_TEST_DIR/valgrind.supp"
127127
}
128128

129129
# No paths below as we can't be sure where the program is!
@@ -2087,7 +2087,7 @@ then
20872087

20882088
# Remove files that can cause problems
20892089
$RM -rf $MYSQL_TEST_DIR/var/ndbcluster
2090-
$RM -f $MYSQL_TEST_DIR/var/run/* $MYSQL_TEST_DIR/var/tmp/*
2090+
$RM -rf $MYSQL_TEST_DIR/var/run/* $MYSQL_TEST_DIR/var/tmp/*
20912091

20922092
# Remove old berkeley db log files that can confuse the server
20932093
$RM -f $MASTER_MYDDIR/log.*

sql-common/client.c

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,29 @@ void set_mysql_error(MYSQL *mysql, int errcode, const char *sqlstate)
753753
DBUG_VOID_RETURN;
754754
}
755755

756+
757+
static void set_mysql_extended_error(MYSQL *mysql, int errcode,
758+
const char *sqlstate,
759+
const char *format, ...)
760+
{
761+
NET *net;
762+
va_list args;
763+
DBUG_ENTER("set_mysql_extended_error");
764+
DBUG_PRINT("enter", ("error :%d '%s'", errcode, format));
765+
DBUG_ASSERT(mysql != 0);
766+
767+
net= &mysql->net;
768+
net->last_errno= errcode;
769+
va_start(args, format);
770+
my_vsnprintf(net->last_error, sizeof(net->last_error)-1,
771+
format, args);
772+
va_end(args);
773+
strmov(net->sqlstate, sqlstate);
774+
775+
DBUG_VOID_RETURN;
776+
}
777+
778+
756779
/*
757780
Flush result set sent from server
758781
*/
@@ -850,6 +873,7 @@ static int check_license(MYSQL *mysql)
850873

851874
void end_server(MYSQL *mysql)
852875
{
876+
int save_errno= errno;
853877
DBUG_ENTER("end_server");
854878
if (mysql->net.vio != 0)
855879
{
@@ -862,6 +886,7 @@ void end_server(MYSQL *mysql)
862886
}
863887
net_end(&mysql->net);
864888
free_old_query(mysql);
889+
errno= save_errno;
865890
DBUG_VOID_RETURN;
866891
}
867892

@@ -2031,7 +2056,10 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
20312056
if (mysql->options.connect_timeout &&
20322057
vio_poll_read(net->vio, mysql->options.connect_timeout))
20332058
{
2034-
set_mysql_error(mysql, CR_SERVER_LOST, unknown_sqlstate);
2059+
set_mysql_extended_error(mysql, CR_SERVER_LOST, unknown_sqlstate,
2060+
ER(CR_SERVER_LOST_EXTENDED),
2061+
"waiting for initial communication packet",
2062+
errno);
20352063
goto error;
20362064
}
20372065

@@ -2040,8 +2068,14 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
20402068
*/
20412069

20422070
if ((pkt_length=cli_safe_read(mysql)) == packet_error)
2071+
{
2072+
if (mysql->net.last_errno == CR_SERVER_LOST)
2073+
set_mysql_extended_error(mysql, CR_SERVER_LOST, unknown_sqlstate,
2074+
ER(CR_SERVER_LOST_EXTENDED),
2075+
"reading initial communication packet",
2076+
errno);
20432077
goto error;
2044-
2078+
}
20452079
/* Check if version of protocol matches current one */
20462080

20472081
mysql->protocol_version= net->read_pos[0];
@@ -2175,7 +2209,10 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
21752209
*/
21762210
if (my_net_write(net,buff,(uint) (end-buff)) || net_flush(net))
21772211
{
2178-
set_mysql_error(mysql, CR_SERVER_LOST, unknown_sqlstate);
2212+
set_mysql_extended_error(mysql, CR_SERVER_LOST, unknown_sqlstate,
2213+
ER(CR_SERVER_LOST_EXTENDED),
2214+
"sending connection information to server",
2215+
errno);
21792216
goto error;
21802217
}
21812218

@@ -2254,7 +2291,10 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
22542291
/* Write authentication package */
22552292
if (my_net_write(net,buff,(ulong) (end-buff)) || net_flush(net))
22562293
{
2257-
set_mysql_error(mysql, CR_SERVER_LOST, unknown_sqlstate);
2294+
set_mysql_extended_error(mysql, CR_SERVER_LOST, unknown_sqlstate,
2295+
ER(CR_SERVER_LOST_EXTENDED),
2296+
"sending authentication information",
2297+
errno);
22582298
goto error;
22592299
}
22602300

@@ -2264,7 +2304,14 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
22642304
*/
22652305

22662306
if ((pkt_length=cli_safe_read(mysql)) == packet_error)
2307+
{
2308+
if (mysql->net.last_errno == CR_SERVER_LOST)
2309+
set_mysql_extended_error(mysql, CR_SERVER_LOST, unknown_sqlstate,
2310+
ER(CR_SERVER_LOST_EXTENDED),
2311+
"reading authorization packet",
2312+
errno);
22672313
goto error;
2314+
}
22682315

22692316
if (pkt_length == 1 && net->read_pos[0] == 254 &&
22702317
mysql->server_capabilities & CLIENT_SECURE_CONNECTION)
@@ -2276,12 +2323,22 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
22762323
scramble_323(buff, mysql->scramble, passwd);
22772324
if (my_net_write(net, buff, SCRAMBLE_LENGTH_323 + 1) || net_flush(net))
22782325
{
2279-
set_mysql_error(mysql, CR_SERVER_LOST, unknown_sqlstate);
2326+
set_mysql_extended_error(mysql, CR_SERVER_LOST, unknown_sqlstate,
2327+
ER(CR_SERVER_LOST_EXTENDED),
2328+
"sending password information",
2329+
errno);
22802330
goto error;
22812331
}
22822332
/* Read what server thinks about out new auth message report */
22832333
if (cli_safe_read(mysql) == packet_error)
2334+
{
2335+
if (mysql->net.last_errno == CR_SERVER_LOST)
2336+
set_mysql_extended_error(mysql, CR_SERVER_LOST, unknown_sqlstate,
2337+
ER(CR_SERVER_LOST_EXTENDED),
2338+
"reading final connect information",
2339+
errno);
22842340
goto error;
2341+
}
22852342
}
22862343

22872344
if (client_flag & CLIENT_COMPRESS) /* We will use compression */
@@ -2292,8 +2349,15 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
22922349
goto error;
22932350
#endif
22942351

2295-
if (db && mysql_select_db(mysql,db))
2352+
if (db && mysql_select_db(mysql, db))
2353+
{
2354+
if (mysql->net.last_errno == CR_SERVER_LOST)
2355+
set_mysql_extended_error(mysql, CR_SERVER_LOST, unknown_sqlstate,
2356+
ER(CR_SERVER_LOST_EXTENDED),
2357+
"Setting intital database",
2358+
errno);
22962359
goto error;
2360+
}
22972361

22982362
if (mysql->options.init_commands)
22992363
{

0 commit comments

Comments
 (0)