summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjluehrs2 <jluehrs2@uiuc.edu>2007-08-17 18:20:07 -0500
committerjluehrs2 <jluehrs2@uiuc.edu>2007-08-17 18:20:07 -0500
commit76a624b683ffa3ad213d8d9a711a82c0f9cbcb82 (patch)
treefe08d813c44b4700547890737542c29029b3469f
parentc10acc99830f6974da0a00650c552732e877587c (diff)
downloadio-pty-easy-76a624b683ffa3ad213d8d9a711a82c0f9cbcb82.tar.gz
io-pty-easy-76a624b683ffa3ad213d8d9a711a82c0f9cbcb82.zip
fix is_active to not rely on SIGCHLD, since it seems to create race conditions that i don't understand
-rw-r--r--lib/IO/Pty/Easy.pm8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/IO/Pty/Easy.pm b/lib/IO/Pty/Easy.pm
index 6467324..36acd9a 100644
--- a/lib/IO/Pty/Easy.pm
+++ b/lib/IO/Pty/Easy.pm
@@ -125,6 +125,8 @@ sub spawn {
# if the exec fails, signal the parent by sending the errno across the pipe
# if the exec succeeds, perl will close the pipe, and the sysread will
# return due to EOF
+ sub sigchld { wait; $SIG{CHLD} = \&sigchld; }
+ $SIG{CHLD} = \&sigchld;
$self->{pid} = fork;
unless ($self->{pid}) {
close $readp;
@@ -175,7 +177,6 @@ sub spawn {
$SIG{WINCH} = $winch;
};
$SIG{WINCH} = $winch if $self->{handle_pty_size};
- $SIG{CHLD} = sub { $self->{pid} = undef; wait };
}
# }}}
@@ -248,7 +249,10 @@ Returns whether or not a subprocess is currently running on the pty.
sub is_active {
my $self = shift;
- return defined($self->{pid});
+ return 0 unless defined($self->{pid});
+ my $active = kill 0 => $self->{pid};
+ delete $self->{pid} unless $active;
+ return $active;
}
# }}}