Signal Handling/Term::ReadLine problem in Perl

Signal Handling/Term::ReadLine problem in Perl

Post by lx » Thu, 22 Jan 2004 10:51:00


I've got an extremely inscrutable problem here using Perl's
Term::ReadLine::Gnu module. I'm using Perl 5.8.0, readline 4.3 and
Term::ReadLine::Gnu 1.14.

The problem is specific to catching INT signals while in the
readline() function. In C, when I've set a SIGINT handler using
signal(), it is immediately called (even in readline()) when I hit
CTRL-C. Likewise in Perl, if I am reading in a while() loop from
STDIN, and I have set the $SIG{INT} handler, it is immediately called
on CTRL-C being struck.

However, the maddening thing here is that when calling readline() from
within Perl, when I hit CTRL-C, it doesn't call the signal handler
until AFTER I hit ENTER on the keyboard. I can even use
tab-completion, reverse-i-search and other readline features after I
have hit CTRL-C, but only after I hit enter, the CTRL-C is processed.

How on earth do I solve this? :) I've googled for over an hour trying
to find a solution and haven't come up with anything. I tried messing
around with some of the Term Attribs to make sure it wasn't using its
own signal handlers but never got different results. Simple script to
duplicate the problem follows.

------------------------------------------------------------------------------
#!/usr/bin/perl
use IO;
use Term::ReadLine;

STDOUT->autoflush();
$SIG{INT} = sub { die("CTRL-C"); };

$term = new Term::ReadLine 'ProgramName';
while (1) {
$input = $term->readline('prompt> ');
print "Got: $input\n";
}

------------------------------------------------------------------------------

Any help would be appreciated!

Best wishes,
John C. Worsley
John C. Worsley - Artist - XXXX@XXXXX.COM
http://www.yqcomputer.com/
 
 
 

1. Getting application ReadLine and Perl debugger ReadLine to cooperate

2. [PATCH] Fix i386 signal handling of NODEFER, should not affect sa_mask (was: Signal handling possibly wrong)


Hmm, I think you want this patch. You still need to check the return of
setting up the frames.

-- Steve

Signed-off-by: Steven Rostedt < XXXX@XXXXX.COM >

--- linux-2.6.13-rc6-git1/arch/i386/kernel/signal.c.orig 2005-08-09 16:54:36.000000000 -0400
+++ linux-2.6.13-rc6-git1/arch/i386/kernel/signal.c 2005-08-09 16:55:24.000000000 -0400
@@ -577,10 +577,11 @@ handle_signal(unsigned long sig, siginfo
else
ret = setup_frame(sig, ka, oldset, regs);

- if (ret && !(ka->sa.sa_flags & SA_NODEFER)) {
+ if (ret) {
spin_lock_irq(¤t->sighand->siglock);
sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask);
- sigaddset(¤t->blocked,sig);
+ if (!(ka->sa.sa_flags & SA_NODEFER))
+ sigaddset(¤t->blocked,sig);
recalc_sigpending();
spin_unlock_irq(¤t->sighand->siglock);
}


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to XXXX@XXXXX.COM
More majordomo info at http://www.yqcomputer.com/
Please read the FAQ at http://www.yqcomputer.com/

3. POSIX signal handling versus traditional signal handling

4. [PATCH] Fix i386 signal handling of NODEFER, should not affect sa_mask (was: Signal handling possibly wrong)

5. POSIX signal handling versus traditional signal handling

6. Python 2.3.3 signals, threads & extensions: signal handling problem

7. Python 2.3.3 signals, threads & extensions: signal handling problem[Resolved]

8. Perl SIG{INT} versus ALSA.so signal handling

9. writing a readline : how to know I am on the last term line ?

10. How to get rid of underline in Term::Readline::GNU's prompt?

11. problem with perl script plug-ins

12. Signal handler doesn`t handle any signals while main thread is blocked

13. threading and signals - main thread solely responsible for signal handling?

14. signal handling and (structured) exception handling

15. gnu readline ruby vs. perl