summaryrefslogtreecommitdiff
path: root/perl5
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2020-02-09 14:09:55 -0700
committerSean Whitton <spwhitton@spwhitton.name>2020-02-09 14:10:14 -0700
commit8621122db6966ed758cf0b7a290312e2cdf99c65 (patch)
tree3d5504cd72401468bb4182d7056556b85b2818e6 /perl5
parent1fec215c7bca447ab81d37cfc5491211cedda824 (diff)
downloaddotfiles-8621122db6966ed758cf0b7a290312e2cdf99c65.tar.gz
let children finish before responding to C-c
Diffstat (limited to 'perl5')
-rw-r--r--perl5/Local/Interactive.pm14
1 files changed, 14 insertions, 0 deletions
diff --git a/perl5/Local/Interactive.pm b/perl5/Local/Interactive.pm
index 5ffbc24e..50f3e06a 100644
--- a/perl5/Local/Interactive.pm
+++ b/perl5/Local/Interactive.pm
@@ -193,12 +193,25 @@ sub _sysptycap_tty {
$slave->clone_winsize_from(\*STDIN) if POSIX::isatty(*STDIN);
$slave->set_raw; # so we can 'sysread' rather than 'read'
local $| = 1;
+
+ # catch SIGINT and allow the current child process to finish up
+ my $interrupted;
+ (my $us = $0) =~ s{^.+/}{};
+ local $SIG{INT}
+ = sub { print STDERR "\n$us: interrupted\n"; $interrupted = 1 };
+
my $pid = fork;
die "fork() failed: $!" unless defined $pid;
unless ($pid) {
$slave->close;
open STDOUT, ">&=", $pty->fileno or die $!;
open STDERR, ">&=", $pty->fileno or die $!;
+
+ # render child processes immune to C-c unless they have their
+ # own signal handlers to perform cleanup, which will override
+ # this
+ $SIG{INT} = $SIG{HUP} = 'IGNORE';
+
exec @_;
}
$pty->close;
@@ -212,6 +225,7 @@ sub _sysptycap_tty {
}
$slave->close;
wait;
+ exit 2 if $interrupted;
return { exit => $? >> 8, output => $output };
}