Subject: | SIGSEGV in Perl debugger after "|" command |
Hi,
this is a forwarded Debian bug report. The original report is at http://bugs.debian.org/236018
When a command is piped to a pager (at least 'less'), Term::Readline::Gnu suffers a SIGSEGV.
The easiest way to reproduce this is as follows:
% gdb /usr/bin/perl
[...]
(gdb) run -de 0
[...]
DB<1> |x
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1075592256 (LWP 7677)]
0x400b520a in fflush () from /lib/tls/libc.so.6
(gdb) bt
#0 0x400b520a in fflush () from /lib/tls/libc.so.6
#1 0x403d67dc in rl_prep_terminal (meta_flag=1) at /home/packages/bash/readline5-5.1/rltty.c:721
#2 0x403d1ecb in readline (prompt=0x0) at /home/packages/bash/readline5-5.1/readline.c:309
#3 0x403a38e9 in XS_Term__ReadLine__Gnu__XS_rl_readline () from /usr/lib/perl5/auto/Term/ReadLine/Gnu/Gnu.so
#4 0x080c0ac0 in Perl_pp_entersub ()
#5 0x080b95aa in Perl_runops_standard ()
#6 0x08064e43 in perl_run ()
#7 0x0805fd4f in main ()
This is verified on Debian GNU/Linux, perl versions 5.8.4 and 5.8.7, and readline 4.3 and 5.1.
It seems to happen because the 'rl_outstream' variable inside the actual
readline library somehow gets out of sync when STDOUT is dup(2)'ed
inside the Perl debugger. This is done for saving and restoring the
file descriptor while using the pager.
The attached patch seems to fix the problem by 'reinitializing' rl_outstream
every time readline() is called.
Cheers,
--
Niko Tyni
ntyni@iki.fi