diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2020-04-15 12:35:39 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2020-04-15 13:31:47 -0700 |
commit | 61ce8f75b9915b1162102f71b5a6542e0f040438 (patch) | |
tree | fc124127e196bf2ced5f9370fde55089fbeb602b /perl5 | |
parent | 1d745b677908ac23c6a97d929a28d6232639155a (diff) | |
download | dotfiles-61ce8f75b9915b1162102f71b5a6542e0f040438.tar.gz |
set $return->{exit} right after waiting on the child
In fact, PID reuse isn't going to happen until child is reaped by
parent.
Diffstat (limited to 'perl5')
-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) |