I need to execute commands through the $ ssh-> system in the background, and it is documented that this should behave the same as the local "system" command:
'As for "system" builtin, "SIGINT" and "SIGQUIT" signals are blocked. (see "system" in perlfunc).'
Actually, it doesn’t look like the ssh-> system in the child case immediately terminates upon receipt of SIGINT, even when I explicitly want "IGNORE" first:
use warnings;
use strict;
use POSIX ":sys_wait_h";
use Net::OpenSSH;
my $CTRLC=0;
$SIG{CHLD}='IGNORE';
sub _int_handler {
$CTRLC++;
print "CTRL-C was pressed $CTRLC times!!!\n";
}
$SIG{INT}='IGNORE';
my $SSH=Net::OpenSSH->new('testhost',
forward_agent => 1,
master_stderr_discard => 1,
master_opts => [ -o =>"PasswordAuthentication=no"]);
$SIG{INT}=\&_int_handler;
sub _ssh {
$SIG{INT}='IGNORE';
$SSH->system('sleep 3; sleep 3');
print "Exiting Child!\n";
exit 0;
}
print "Starting shell ...\n";
_ssh if not (my $PID=fork);
print $PID, "\n";
waitpid ($PID,0);
When you run this code and try to interrupt immediately after starting the first "sleep 3" call "$ SSH->" immediately stops.
If you, however, use the local "system" instruction just below, SIGINT is caught correctly.
Net:: OpenSSH , $SIG {INT} "IGNORE" "system" . , .
, -. , - CTRL-C.
,
Mazze
UPDATE:
@salva. , , "-S" ssh:
$SIG{INT}='IGNORE';
system('ssh lnx0001a -- sleep 3');
"-S/tmp/mysock", ssh, , , . -, ?
, ?
,
Mazze
2:
, - . :
$ trap '' INT
$ ssh lnx0001a -- sleep 3
.
, , :
$ ssh -S /tmp/mysock lnx0001a -- sleep 3
CTRL-C . root, , . @ENV, , .
: "-S" "trap" "INT" ?
(, - /tmp/mysock ).
,
Mazze