<?xml version="1.0" encoding="windows-1252"?>
<node id="1003702" title="Re: Perl Term::ReadLine::Gnu Signal Handling Difficulties" created="2012-11-13 15:32:31" updated="2012-11-13 15:32:31">
<type id="11">
note</type>
<author id="155876">
Mr. Muskrat</author>
<data>
<field name="doctext">
&lt;p&gt;Well, I have been setting up some new servers today (mounting them in the rack, running cables, etc) and haven't have much time to look at this.&lt;/p&gt;
&lt;p&gt;I did find something interesting though. [http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=160328] It seems that when Perl's safe signals were introduced, it broke [mod://Term::ReadLine::Gnu].&lt;/p&gt;
&lt;p&gt;Do you need to use [mod://Term::ReadLine::Gnu] or can you use [mod://Term::ReadLine::Perl] (where this still works)?&lt;/p&gt;
&lt;p&gt;If you do need it to use [mod://Term::ReadLine::Gnu] then perhaps this will work for you. Beware though! It uses unsafe signals so it can cause all sorts of nasty things to happen to the Perl process. Oh and it seems to leave the terminal in an odd state when a signal forces it to bail out.&lt;/p&gt;
&lt;code&gt;
#!/usr/bin/perl
use strict;
use warnings;
BEGIN {
    $ENV{PERL_RL} = 'Gnu'; # or 'Perl' to force which one to use
}
use Term::ReadLine;
use Signal::Safety;

my $term = Term::ReadLine-&gt;new('Term1');
print "Readline: ", $term-&gt;ReadLine, "\n";
$term-&gt;ornaments(0);
my $attribs = $term-&gt;Attribs;
$attribs-&gt;{catch_signals} = 0;

$SIG{TERM} = sub { print "I got a TERM\n"; exit; };
$SIG{INT} = sub { print "I got a INT\n"; exit; };
# add any additional signal handlers you want

my $prompt = 'cmd&gt; ';
my $cmd = '';
while ( defined $cmd ) {
    {
        local $Signal::Safety = 0; # limit the use of unsafe signals
        $cmd = $term-&gt;readline($prompt);
    }
    chomp($cmd);
    if ($cmd =~ /^help$/) {
        print "Help Menu\n";
    }
    else {
        print "Nothing\n";
    }
}
&lt;/code&gt;
</field>
<field name="root_node">
1003497</field>
<field name="parent_node">
1003497</field>
</data>
</node>
