Merge lp:~sergei.glushchenko/percona-server/ST30462-bug925343-5.6 into lp:percona-server/5.6

Proposed by Sergei Glushchenko
Status: Merged
Approved by: Stewart Smith
Approved revision: no longer in the source branch.
Merged at revision: 331
Proposed branch: lp:~sergei.glushchenko/percona-server/ST30462-bug925343-5.6
Merge into: lp:percona-server/5.6
Diff against target: 66 lines (+7/-16)
1 file modified
Percona-Server/client/mysql.cc (+7/-16)
To merge this branch: bzr merge lp:~sergei.glushchenko/percona-server/ST30462-bug925343-5.6
Reviewer Review Type Date Requested Status
Stewart Smith (community) Approve
Review via email: mp+156862@code.launchpad.net

Description of the change

Bug 925343: mysql client aborts connection on terminal resize.
Fix for upstream bug #26780 "patch to add auto vertical output
option to the cli" introduced SIGWINCH handling by mysql cli.
This leads to EINTR to be returned by read call on socket.
On most systems there is a possibility for read call
to be automatically restarted if SA_RESTART flag is set for
the signal. Hovewer this is not the case, as read timeout on
socket has been set. Linux manual page for signal(7) tells that
there is no chance for read to be restarted if timeout has
been set on socket. It doesn't matter whether SA_RESTART has
been used for signal or not.
So the only portable solution would be to block signal for the
time when client communicates with server. This however would
require a lot of carefull code reading to spot all the point
of such communication in source code and wrap them with
block/unblock signal.
That is why option to completely disable SIGWINCH handling
has been choosen. The only purpose of SIGWINCH handler was to
determine new width of terminal window. The only place where
this width is used is to print output from the server.
Handling of SIGWINCH has been replaced with explicit invocation
of ioctl to get terminal width just before print of result set
is started.

http://jenkins.percona.com/view/PS%205.6/job/percona-server-5.6-param/74/

To post a comment you must log in.
Revision history for this message
Stewart Smith (stewart) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Percona-Server/client/mysql.cc'
--- Percona-Server/client/mysql.cc 2013-03-05 12:46:43 +0000
+++ Percona-Server/client/mysql.cc 2013-04-04 09:42:24 +0000
@@ -202,7 +202,6 @@
202static uint prompt_counter;202static uint prompt_counter;
203static char delimiter[16]= DEFAULT_DELIMITER;203static char delimiter[16]= DEFAULT_DELIMITER;
204static uint delimiter_length= 1;204static uint delimiter_length= 1;
205unsigned short terminal_width= 80;
206205
207#ifdef HAVE_SMEM206#ifdef HAVE_SMEM
208static char *shared_memory_base_name=0;207static char *shared_memory_base_name=0;
@@ -1128,9 +1127,7 @@
1128static void nice_time(double sec,char *buff,bool part_second);1127static void nice_time(double sec,char *buff,bool part_second);
1129extern "C" sig_handler mysql_end(int sig);1128extern "C" sig_handler mysql_end(int sig);
1130extern "C" sig_handler handle_kill_signal(int sig);1129extern "C" sig_handler handle_kill_signal(int sig);
1131#if defined(HAVE_TERMIOS_H) && defined(GWINSZ_IN_SYS_IOCTL)1130static unsigned short get_terminal_width();
1132static sig_handler window_resize(int sig);
1133#endif
11341131
1135const char DELIMITER_NAME[]= "delimiter";1132const char DELIMITER_NAME[]= "delimiter";
1136const uint DELIMITER_NAME_LEN= sizeof(DELIMITER_NAME) - 1;1133const uint DELIMITER_NAME_LEN= sizeof(DELIMITER_NAME) - 1;
@@ -1305,13 +1302,6 @@
1305#endif1302#endif
13061303
13071304
1308#if defined(HAVE_TERMIOS_H) && defined(GWINSZ_IN_SYS_IOCTL)
1309 /* Readline will call this if it installs a handler */
1310 signal(SIGWINCH, window_resize);
1311 /* call the SIGWINCH handler to get the default term width */
1312 window_resize(0);
1313#endif
1314
1315 put_info("Welcome to the MySQL monitor. Commands end with ; or \\g.",1305 put_info("Welcome to the MySQL monitor. Commands end with ; or \\g.",
1316 INFO_INFO);1306 INFO_INFO);
1317 sprintf((char*) glob_buffer.ptr(),1307 sprintf((char*) glob_buffer.ptr(),
@@ -1515,15 +1505,16 @@
1515}1505}
15161506
15171507
1508unsigned short get_terminal_width()
1509{
1518#if defined(HAVE_TERMIOS_H) && defined(GWINSZ_IN_SYS_IOCTL)1510#if defined(HAVE_TERMIOS_H) && defined(GWINSZ_IN_SYS_IOCTL)
1519sig_handler window_resize(int sig)
1520{
1521 struct winsize window_size;1511 struct winsize window_size;
15221512
1523 if (ioctl(fileno(stdin), TIOCGWINSZ, &window_size) == 0)1513 if (ioctl(fileno(stdin), TIOCGWINSZ, &window_size) == 0)
1524 terminal_width= window_size.ws_col;1514 return window_size.ws_col;
1515#endif
1516 return 80;
1525}1517}
1526#endif
15271518
1528static struct my_option my_long_options[] =1519static struct my_option my_long_options[] =
1529{1520{
@@ -3435,7 +3426,7 @@
3435 print_table_data_html(result);3426 print_table_data_html(result);
3436 else if (opt_xml)3427 else if (opt_xml)
3437 print_table_data_xml(result);3428 print_table_data_xml(result);
3438 else if (vertical || (auto_vertical_output && (terminal_width < get_result_width(result))))3429 else if (vertical || (auto_vertical_output && (get_terminal_width() < get_result_width(result))))
3439 print_table_data_vertically(result);3430 print_table_data_vertically(result);
3440 else if (opt_silent && verbose <= 2 && !output_tables)3431 else if (opt_silent && verbose <= 2 && !output_tables)
3441 print_tab_data(result);3432 print_tab_data(result);

Subscribers

People subscribed via source and target branches