an3l / my_playground

My playground with python, nginx, docker and server!
0 stars 0 forks source link

MDEV-14448: Ctrl-C should not exit the client #6

Open an3l opened 5 years ago

an3l commented 5 years ago

This issue is analysis of PR#703. Short notes:

Inspection:


an3l commented 5 years ago

Review

Testing

mysql

In mysql invoking SIGINT output is going in the next row (in his patch we have to press enter again)

mysql> use test;^C
mysql> ^C
mysql> ^C

Patch PR#703

MariaDB [(none)]> (SIGINT), (ENTER) # not good
MariaDB [(none)]>  ^C

Reasong is that mysql is using cmd-line-utils/libedit/readline.c while we are using extra/readline.h which are different.

Debugging

mysql

# Enable SIGINT
gdb -> handle SIGINT pass

b handle_ctrlc_signal

mysql> 
Program received signal SIGINT, Interrupt.
0x00007ffff7bc734e in __libc_read (fd=0, buf=0x7fffffffd8b0, nbytes=1) at ../sysdeps/unix/sysv/linux/read.c:27

(gdb) bt
#0  0x00007ffff7bc734e in __libc_read (fd=0, buf=0x7fffffffd8b0, nbytes=1) at ../sysdeps/unix/sysv/linux/read.c:27
#1  0x000055555568cedd in read_char (el=0x555555c58110, cp=0x7fffffffd97c L" \001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:315
#2  0x000055555568d13e in el_wgetc (el=0x555555c58110, cp=0x7fffffffd97c L" \001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:433
#3  0x000055555568cca5 in read_getcmd (el=0x555555c58110, cmdnum=0x7fffffffd97b "\b ", ch=0x7fffffffd97c L" \001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:246
#4  0x000055555568d534 in el_wgets (el=0x555555c58110, nread=0x7fffffffda00) at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:578
#5  0x0000555555682e81 in el_gets (el=0x555555c58110, nread=0x7fffffffda00) at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/eln.c:74
#6  0x0000555555677b65 in readline (p=0x555555c85400 "mysql> ") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/readline.c:441
#7  0x000055555558d14f in read_and_execute (interactive=true) at /home/anel/workspace/mariadb/mysql-server/client/mysql.cc:2315
#8  0x000055555558bd9e in main (argc=5, argv=0x555555c4a060) at /home/anel/workspace/mariadb/mysql-server/client/mysql.cc:1447

(gdb) info b
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x000055555558c0d3 in handle_ctrlc_signal(int) at /home/anel/workspace/mariadb/mysql-server/client/mysql.cc:1534
        breakpoint already hit 1 time

(gdb) n
sig_handler (signo=2) at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/sig.c:69
(gdb) bt

#0  sig_handler (signo=32767) at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/sig.c:69
#1  <signal handler called>
#2  0x00007ffff7bc734e in __libc_read (fd=0, buf=0x7fffffffd8b0, nbytes=1) at ../sysdeps/unix/sysv/linux/read.c:27
#3  0x000055555568cedd in read_char (el=0x555555c58110, cp=0x7fffffffd97c L"t\001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:315
#4  0x000055555568d13e in el_wgetc (el=0x555555c58110, cp=0x7fffffffd97c L"t\001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:433
#5  0x000055555568cca5 in read_getcmd (el=0x555555c58110, cmdnum=0x7fffffffd97b "\bt", ch=0x7fffffffd97c L"t\001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:246
#6  0x000055555568d534 in el_wgets (el=0x555555c58110, nread=0x7fffffffda00) at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:578
#7  0x0000555555682e81 in el_gets (el=0x555555c58110, nread=0x7fffffffda00) at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/eln.c:74
#8  0x0000555555677b65 in readline (p=0x555555c85400 "mysql> ") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/readline.c:441
#9  0x000055555558d14f in read_and_execute (interactive=true) at /home/anel/workspace/mariadb/mysql-server/client/mysql.cc:2315
#10 0x000055555558bd9e in main (argc=5, argv=0x555555c4a060) at /home/anel/workspace/mariadb/mysql-server/client/mysql.cc:1447

(gdb) c
Continuing.

Program received signal SIGINT, Interrupt.
0x00007ffff7bc734e in __libc_read (fd=0, buf=0x7fffffffd8b0, nbytes=1) at ../sysdeps/unix/sysv/linux/read.c:27
(gdb) bt
#0  0x00007ffff7bc734e in __libc_read (fd=0, buf=0x7fffffffd8b0, nbytes=1) at ../sysdeps/unix/sysv/linux/read.c:27
#1  0x000055555568cedd in read_char (el=0x555555c58110, cp=0x7fffffffd97c L"缀\001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:315
#2  0x000055555568d13e in el_wgetc (el=0x555555c58110, cp=0x7fffffffd97c L"缀\001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:433
#3  0x000055555568cca5 in read_getcmd (el=0x555555c58110, cmdnum=0x7fffffffd97b "", ch=0x7fffffffd97c L"缀\001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:246
#4  0x000055555568d534 in el_wgets (el=0x555555c58110, nread=0x7fffffffda00) at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:578
#5  0x0000555555682e81 in el_gets (el=0x555555c58110, nread=0x7fffffffda00) at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/eln.c:74
#6  0x0000555555677b65 in readline (p=0x555555c85400 "mysql> ") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/readline.c:441
#7  0x000055555558d14f in read_and_execute (interactive=true) at /home/anel/workspace/mariadb/mysql-server/client/mysql.cc:2315
#8  0x000055555558bd9e in main (argc=5, argv=0x555555c4a060) at /home/anel/workspace/mariadb/mysql-server/client/mysql.cc:1447
(gdb) n
handle_ctrlc_signal (sig=-737690969) at /home/anel/workspace/mariadb/mysql-server/client/mysql.cc:1533

(gdb) bt
#0  handle_ctrlc_signal (sig=-737690969) at /home/anel/workspace/mariadb/mysql-server/client/mysql.cc:1533
#1  <signal handler called>
#2  0x00007ffff7bc734e in __libc_read (fd=0, buf=0x7fffffffd8b0, nbytes=1) at ../sysdeps/unix/sysv/linux/read.c:27
#3  0x000055555568cedd in read_char (el=0x555555c58110, cp=0x7fffffffd97c L" \001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:315
#4  0x000055555568d13e in el_wgetc (el=0x555555c58110, cp=0x7fffffffd97c L" \001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:433
#5  0x000055555568cca5 in read_getcmd (el=0x555555c58110, cmdnum=0x7fffffffd97b "\b ", ch=0x7fffffffd97c L" \001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:246
#6  0x000055555568d534 in el_wgets (el=0x555555c58110, nread=0x7fffffffda00) at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:578
#7  0x0000555555682e81 in el_gets (el=0x555555c58110, nread=0x7fffffffda00) at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/eln.c:74
#8  0x0000555555677b65 in readline (p=0x555555c85400 "mysql> ") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/readline.c:441
#9  0x000055555558d14f in read_and_execute (interactive=true) at /home/anel/workspace/mariadb/mysql-server/client/mysql.cc:2315
#10 0x000055555558bd9e in main (argc=5, argv=0x555555c4a060) at /home/anel/workspace/mariadb/mysql-server/client/mysql.cc:1447

c
n

#0  handle_ctrlc_signal (sig=2) at /home/anel/workspace/mariadb/mysql-server/client/mysql.cc:1537
#1  <signal handler called>
#2  0x00007ffff7bc734e in __libc_read (fd=0, buf=0x7fffffffd8b0, nbytes=1) at ../sysdeps/unix/sysv/linux/read.c:27
#3  0x000055555568cedd in read_char (el=0x555555c58110, cp=0x7fffffffd97c L"t\001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:315
#4  0x000055555568d13e in el_wgetc (el=0x555555c58110, cp=0x7fffffffd97c L"t\001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:433
#5  0x000055555568cca5 in read_getcmd (el=0x555555c58110, cmdnum=0x7fffffffd97b "\bt", ch=0x7fffffffd97c L"t\001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:246
#6  0x000055555568d534 in el_wgets (el=0x555555c58110, nread=0x7fffffffda00) at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:578
#7  0x0000555555682e81 in el_gets (el=0x555555c58110, nread=0x7fffffffda00) at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/eln.c:74
#8  0x0000555555677b65 in readline (p=0x555555c85400 "mysql> ") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/readline.c:441
#9  0x000055555558d14f in read_and_execute (interactive=true) at /home/anel/workspace/mariadb/mysql-server/client/mysql.cc:2315
#10 0x000055555558bd9e in main (argc=5, argv=0x555555c4a060) at /home/anel/workspace/mariadb/mysql-server/client/mysql.cc:1447

execute_query is not invoked !

read_char (el=0x555555c58110, cp=0x7fffffffd97c L"t\001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:316
        case SIGINT:                                                                                                                                                                                                                                          │

│325 goto end; end: return (int)num_read; │ │373 }


el_wgets (el=0x555555c58110, nread=0x7fffffffda00) at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:585

 terminal__flush(el);            /* flush any buffered output */                                                                                                                                                                                               │
   │705             /* make sure the tty is set up correctly */ 

Patch PR#703

(gdb) n
rl_signal_handler (sig=0) at extra/readline/signals.c:118
(gdb) bt
#0  rl_signal_handler (sig=0) at extra/readline/signals.c:118
#1  <signal handler called>
#2  0x00007ffff7bc734e in __libc_read (fd=0, buf=0x7fffffffd9cb, nbytes=1) at ../sysdeps/unix/sysv/linux/read.c:27
#3  0x00005555556299c0 in rl_getc (stream=0x7ffff669ea00 <_IO_2_1_stdin_>) at extra/readline/input.c:466
#4  0x000055555562998b in rl_read_key () at extra/readline/input.c:446
#5  0x000055555561268c in readline_internal_char () at extra/readline/readline.c:482
#6  0x00005555556127c4 in readline_internal_charloop () at extra/readline/readline.c:543
#7  0x00005555556127f0 in readline_internal () at extra/readline/readline.c:557
#8  0x0000555555612253 in readline (prompt=0x555555bf76a8 "MariaDB [(none)]> ") at extra/readline/readline.c:320
#9  0x00005555555b5040 in read_and_execute (interactive=true) at client/mysql.cc:2154
#10 0x00005555555b3ad4 in main (argc=1, argv=0x555555bee2b0) at client/mysql.cc:1291

(gdb) n
Program received signal SIGINT, Interrupt.
0x00007ffff62f214d in __GI___sigprocmask (how=2, set=0x7fffffffd370, oset=0x0)
    at ../sysdeps/unix/sysv/linux/x86_64/sigprocmask.c:36
(gdb) bt
#0  0x00007ffff62f214d in __GI___sigprocmask (how=2, set=0x7fffffffd370, oset=0x0)
    at ../sysdeps/unix/sysv/linux/x86_64/sigprocmask.c:36
#1  0x0000555555626854 in rl_signal_handler (sig=2) at extra/readline/signals.c:184
#2  <signal handler called>
#3  0x00007ffff7bc734e in __libc_read (fd=0, buf=0x7fffffffd9cb, nbytes=1) at ../sysdeps/unix/sysv/linux/read.c:27
#4  0x00005555556299c0 in rl_getc (stream=0x7ffff669ea00 <_IO_2_1_stdin_>) at extra/readline/input.c:466
#5  0x000055555562998b in rl_read_key () at extra/readline/input.c:446
#6  0x000055555561268c in readline_internal_char () at extra/readline/readline.c:482
#7  0x00005555556127c4 in readline_internal_charloop () at extra/readline/readline.c:543
#8  0x00005555556127f0 in readline_internal () at extra/readline/readline.c:557
#9  0x0000555555612253 in readline (prompt=0x555555bf76a8 "MariaDB [(none)]> ") at extra/readline/readline.c:320
#10 0x00005555555b5040 in read_and_execute (interactive=true) at client/mysql.cc:2154
#11 0x00005555555b3ad4 in main (argc=1, argv=0x555555bee2b0) at client/mysql.cc:1291

(gdb) n
handle_ctrlc_signal (sig=32767) at client/mysql.cc:1310
(gdb) bt
#0  handle_ctrlc_signal (sig=32767) at client/mysql.cc:1310
#1  <signal handler called>
#2  0x00007ffff62f214d in __GI___sigprocmask (how=2, set=0x7fffffffd370, oset=0x0)
    at ../sysdeps/unix/sysv/linux/x86_64/sigprocmask.c:36
#3  0x0000555555626854 in rl_signal_handler (sig=2) at extra/readline/signals.c:184
#4  <signal handler called>
#5  0x00007ffff7bc734e in __libc_read (fd=0, buf=0x7fffffffd9cb, nbytes=1) at ../sysdeps/unix/sysv/linux/read.c:27
#6  0x00005555556299c0 in rl_getc (stream=0x7ffff669ea00 <_IO_2_1_stdin_>) at extra/readline/input.c:466
#7  0x000055555562998b in rl_read_key () at extra/readline/input.c:446
#8  0x000055555561268c in readline_internal_char () at extra/readline/readline.c:482
#9  0x00005555556127c4 in readline_internal_charloop () at extra/readline/readline.c:543
#10 0x00005555556127f0 in readline_internal () at extra/readline/readline.c:557
#11 0x0000555555612253 in readline (prompt=0x555555bf76a8 "MariaDB [(none)]> ") at extra/readline/readline.c:320
#12 0x00005555555b5040 in read_and_execute (interactive=true) at client/mysql.cc:2154
#13 0x00005555555b3ad4 in main (argc=1, argv=0x555555bee2b0) at client/mysql.cc:1291

Conclusion

Write own patch with handling signal(SIGINT) and in signal handler (longjump or better readline library support) readline library functions passing sigint

an3l commented 5 years ago

Playing with readline: Create ~/.inputrc. There is global inputrc in /etc/inputrc. See info rluserman and man readline (3-library calls(functions within program libraries) locate readline.so Incremental C-r, non-incremental M(meta-Alt)-p search List symbols from dynamic object files nm -D /bin/bash |grep readline in general list conente of library (.so) with nm filename Install readline development libraries sudo apt-get install libreadline-dev Compiler(header-> -Idir or CPATH environment variables "include-paths", in /usr/include/ there is a readline/readline.h and 'math.h', since header filename is know only directory is needed). Include paths of "Gnu preprocessor " cpp -v Linker(libraries are needed to resolve external dependencies, "libraries-path", -Ldir or LIBRARY_PATH and library name -lmath-> linker needs to know directory and library name) GCC uses the following environment variables:

<stdio.h> should be included before readline.h RL_READLINE_VERSION in hex format new object types, all pointers to functions. gcc manual readline library global offset table -got

an3l commented 5 years ago

Raised PR #1308 in mariadb server