$ SIG {INT} = 'IGNORE' does not work with Net :: OpenSSH

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');
#       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 -S /tmp/mysock lnx0001a -- sleep 3');
  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

+4
2

, , CTRL-C , ​​ (. SIGINT ).

, , , , reset , .

, SSH . RT, , .

. , OpenSSH system :

my @cmd = $SSH->make_remote_command("sleep 3 && echo hello");
warn "running command @cmd\n";
local $SIG{INT} = 'IGNORE';
system @cmd;

, , ssh, INT IGNORE.

2. , SSH-, . , INT.

, , - , .

3: (0.61_15).

...

my $ssh = Net::OpenSSH->new($host, master_setpgrp => 1, ...);
$ssh->system({setpgrp => 1}, "sleep 10; echo uninterruptible");

... , , SIGINT SSH-.

, , !

+3

pre-Perl-5.8, var PERL_SIGNALS "".

Perl 5.8.1 : perlipc: ( )

, , , , - , : perlrun: PERL_SIGNALS

:

 $ENV{'PERL_SIGNALS'} = 'unsafe';

:)

, . , , - .

+1

Source: https://habr.com/ru/post/1534476/


All Articles