Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite168dfe

Browse files
committed
Cope with Readline's failure to track SIGWINCH events outside of input.
It emerges that libreadline doesn't notice terminal window size changeevents unless they occur while collecting input. This is easy to stumbleover if you resize the window while using a pager to look at query output,but it can be demonstrated without any pager involvement. The symptom isthat queries exceeding one line are misdisplayed during subsequent inputcycles, because libreadline has the wrong idea of the screen dimensions.The safest, simplest way to fix this is to call rl_reset_screen_size()just before calling readline(). That causes an extra ioctl(TIOCGWINSZ)for every command; but since it only happens when reading from a tty, theperformance impact should be negligible. A more valid objection is thatthis still leaves a tiny window during entry to readline() wherein deliveryof SIGWINCH will be missed; but the practical consequences of that areprobably negligible. In any case, there doesn't seem to be any good way toavoid the race, since readline exposes no functions that seem safe to callfrom a generic signal handler --- rl_reset_screen_size() certainly isn't.It turns out that we also need an explicit rl_initialize() call, elserl_reset_screen_size() dumps core when called before the first readline()call.rl_reset_screen_size() is not present in old versions of libreadline,so we need a configure test for that. (rl_initialize() is present atleast back to readline 4.0, so we won't bother with a test for it.)We would need a configure test anyway since libedit's emulation oflibreadline doesn't currently include such a function. Fortunately,libedit seems not to have any corresponding bug.Merlin Moncure, adjusted a bit by me
1 parentb9a46f8 commite168dfe

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

‎configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12415,7 +12415,7 @@ if test x"$pgac_cv_var_rl_completion_append_character" = x"yes"; then
1241512415
$as_echo"#define HAVE_RL_COMPLETION_APPEND_CHARACTER 1">>confdefs.h
1241612416

1241712417
fi
12418-
forac_funcin rl_completion_matches rl_filename_completion_function
12418+
forac_funcin rl_completion_matches rl_filename_completion_function rl_reset_screen_size
1241912419
do:
1242012420
as_ac_var=`$as_echo"ac_cv_func_$ac_func"|$as_tr_sh`
1242112421
ac_fn_c_check_func"$LINENO""$ac_func""$as_ac_var"

‎configure.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,7 @@ LIBS="$LIBS_including_readline"
15451545

15461546
if test "$with_readline" = yes; then
15471547
PGAC_VAR_RL_COMPLETION_APPEND_CHARACTER
1548-
AC_CHECK_FUNCS([rl_completion_matches rl_filename_completion_function])
1548+
AC_CHECK_FUNCS([rl_completion_matches rl_filename_completion_function rl_reset_screen_size])
15491549
AC_CHECK_FUNCS([append_history history_truncate_file])
15501550
fi
15511551

‎src/bin/psql/input.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ gets_interactive(const char *prompt)
6565
{
6666
char*result;
6767

68+
/*
69+
* Some versions of readline don't notice SIGWINCH signals that arrive
70+
* when not actively reading input. The simplest fix is to always
71+
* re-read the terminal size. This leaves a window for SIGWINCH to be
72+
* missed between here and where readline() enables libreadline's
73+
* signal handler, but that's probably short enough to be ignored.
74+
*/
75+
#ifdefHAVE_RL_RESET_SCREEN_SIZE
76+
rl_reset_screen_size();
77+
#endif
78+
6879
/* Enable SIGINT to longjmp to sigint_interrupt_jmp */
6980
sigint_interrupt_enabled= true;
7081

@@ -330,6 +341,7 @@ initializeInput(int flags)
330341
charhome[MAXPGPATH];
331342

332343
useReadline= true;
344+
rl_initialize();
333345
initialize_readline();
334346

335347
useHistory= true;

‎src/include/pg_config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,9 @@
406406
/* Define to 1 if you have the `rl_filename_completion_function' function. */
407407
#undef HAVE_RL_FILENAME_COMPLETION_FUNCTION
408408

409+
/* Define to 1 if you have the `rl_reset_screen_size' function. */
410+
#undef HAVE_RL_RESET_SCREEN_SIZE
411+
409412
/* Define to 1 if you have the <security/pam_appl.h> header file. */
410413
#undef HAVE_SECURITY_PAM_APPL_H
411414

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp