diff options
Diffstat (limited to 'perl5/Local/Interactive.pm')
-rw-r--r-- | perl5/Local/Interactive.pm | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/perl5/Local/Interactive.pm b/perl5/Local/Interactive.pm index df6cdc32..bac754a4 100644 --- a/perl5/Local/Interactive.pm +++ b/perl5/Local/Interactive.pm @@ -225,22 +225,19 @@ sub _sysptycap_pty { while (1) { my $rin = ""; vec($rin, fileno $slave, 1) = 1; - if (select $rin, undef, undef, 1) { - my $nbytes = sysread $slave, my $bytes, 8192; - last if defined $nbytes and $nbytes == 0; + my $nbytes = sysread $slave, my $bytes, 8192 + if select $rin, undef, undef, 1; + if ($nbytes) { print $bytes; $return->{output} .= $bytes; - } else { - # Since there was no new output, see if child needs - # reaping, and end the loop if all children have died. - # This is needed as the child might die without the pty - # getting EOF, e.g. if an SSH control socket is still - # alive (seems to happen when using Debian's SSH jump host - # to SSH to salsa). - # - # An alternative is to make the whole loop 'while (kill 0, - # $pid)' but this is more elegant as PIDs get reused - last if waitpid(-1, WNOHANG) == -1; + } elsif (my $deceased = waitpid $pid, WNOHANG) { + # As there was no new output, or we got EOF, check if the + # child has died. We can't just check for EOF alone + # because we can't rely on the pty getting EOF, e.g. if an + # SSH control socket is still alive (seems to happen when + # using Debian's SSH jump host to SSH to salsa) + $return->{exit} = $? >> 8 if $deceased > 0; + last; } } $slave->close; @@ -250,8 +247,7 @@ sub _sysptycap_pty { my $codeset = eval { langinfo CODESET }; $return->{output} = decode $codeset, $return->{output} if $codeset; - $return->{exit} = $? >> 8; - return $return; + $return; } =head prompt($prompt) |