diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2020-04-15 00:00:59 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2020-04-15 00:02:19 -0700 |
commit | 07543134aec05945b27f036def1a3a9eb95f2079 (patch) | |
tree | 642352df4b417da7eb8bc04319d558e4b4d3c7a5 /perl5 | |
parent | 49748fdfcf2aeeb6195563691bc38288d6d6f0d7 (diff) | |
download | dotfiles-07543134aec05945b27f036def1a3a9eb95f2079.tar.gz |
rather than relying on literal PIDs, break look if no more children
This is more elegant as PIDs get reused.
Diffstat (limited to 'perl5')
-rw-r--r-- | perl5/Local/Interactive.pm | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/perl5/Local/Interactive.pm b/perl5/Local/Interactive.pm index fa66d18e..631e4c6a 100644 --- a/perl5/Local/Interactive.pm +++ b/perl5/Local/Interactive.pm @@ -216,11 +216,7 @@ sub _sysptycap_tty { } $pty->close; my $output; - # don't continue trying to read if child has 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) - while (kill 0, $pid) { + while (1) { my $rin = ""; vec($rin, fileno $slave, 1) = 1; if (select $rin, undef, undef, 1) { @@ -229,8 +225,16 @@ sub _sysptycap_tty { print $chars; $output .= $chars; } else { - # since there was no new output, see if child needs reaping - waitpid -1, &WNOHANG; + # 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; } } $slave->close; |