From 4e21bde42072a32e0a7cc515546ce9f13ecc8833 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 4 Mar 2012 22:32:13 -0600 Subject: close the pty before killing the underlying process interactive shells typically block SIGTERM, but do exit when they receive EOF. this gives them the opportunity to terminate themselves, before doing it more explicitly. --- lib/IO/Pty/Easy.pm | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/IO/Pty/Easy.pm b/lib/IO/Pty/Easy.pm index 2953f1d..904fbd5 100644 --- a/lib/IO/Pty/Easy.pm +++ b/lib/IO/Pty/Easy.pm @@ -261,15 +261,18 @@ sub is_active { my $self = shift; return 0 unless defined $self->pid; - # XXX FreeBSD 7.0 will not allow a session leader to exit until the kernel - # tty output buffer is empty. Make it so. - my $rin = ''; - vec($rin, fileno($self), 1) = 1; - my $nfound = select($rin, undef, undef, 0); - if ($nfound > 0) { - sysread($self, ${*{$self}}{io_pty_easy_final_output}, - $self->def_max_read_chars, - length ${*{$self}}{io_pty_easy_final_output}); + + if (defined(my $fd = fileno($self))) { + # XXX FreeBSD 7.0 will not allow a session leader to exit until the + # kernel tty output buffer is empty. Make it so. + my $rin = ''; + vec($rin, $fd, 1) = 1; + my $nfound = select($rin, undef, undef, 0); + if ($nfound > 0) { + sysread($self, ${*{$self}}{io_pty_easy_final_output}, + $self->def_max_read_chars, + length ${*{$self}}{io_pty_easy_final_output}); + } } my $active = kill 0 => $self->pid; @@ -322,8 +325,8 @@ this call. sub close { my $self = shift; - $self->kill; close $self; + $self->kill; } =head2 handle_pty_size() -- cgit v1.2.3-54-g00ecf