summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-03-04 22:32:13 -0600
committerJesse Luehrs <doy@tozt.net>2012-03-04 22:32:13 -0600
commit4e21bde42072a32e0a7cc515546ce9f13ecc8833 (patch)
treedc99cef2b41c9c48b6b65d90e3ceab5a692d08ce
parentb087734e8cb866baa6a1cf12b3daf23d9e0f1531 (diff)
downloadio-pty-easy-4e21bde42072a32e0a7cc515546ce9f13ecc8833.tar.gz
io-pty-easy-4e21bde42072a32e0a7cc515546ce9f13ecc8833.zip
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.
-rw-r--r--lib/IO/Pty/Easy.pm23
1 files changed, 13 insertions, 10 deletions
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()