differenceengine has asked for the wisdom of the Perl Monks concerning the following question:
Greetings monks...
I have a Perl program which is an interactive shell style affair which is run by sshd on a remote server via sshd's ForceCommand. So I can ssh to one of my servers and I get to issue commands to my Perl program to run other Perl scripts which carry out system maintenance etc. It all works quite nicely. But if I want to tail -f a file like so...
if($cmd[0] eq "tail") { open(TAIL,"|tail -f /var/log/messages"); while(<TAIL>) { print $_; } } }
... I need a way to break out of it. So I came up with this...
if($cmd[0] eq "tail") { open(TAIL,"|tail -f /var/log/messages"); my $tailing = 1; sub __int_tail { $tailing = 0; } $SIG{'INT'} = \&__int_tail; while($tailing) { while(<TAIL>) { print $_; } } return 0; }
... which works perfectly if I run if I run my Perl shell from a real shell. But if I ssh to my host the SIGINT gets captured by the ssh client on the local host.
So the question is, how do I capture or override SIGINT in a parent process that has forked (?) Perl? In fact, what even is the parent process in this case? sshd, a pseudo tty, my ssh client?
I guess this can be done because a real Unix shell in a ssh session can capture Ctrl-C issued locally and use it on the remote session.
Any wisdom would be most appreciated!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl SIG INT handling conundrum.
by Neighbour (Friar) on Aug 16, 2011 at 14:51 UTC | |
|
Re: Perl SIG INT handling conundrum.
by qleem (Initiate) on Aug 16, 2011 at 18:16 UTC | |
by differenceengine (Novice) on Aug 16, 2011 at 18:38 UTC | |
by differenceengine (Novice) on Aug 16, 2011 at 18:57 UTC |