From 76a624b683ffa3ad213d8d9a711a82c0f9cbcb82 Mon Sep 17 00:00:00 2001 From: jluehrs2 Date: Fri, 17 Aug 2007 18:20:07 -0500 Subject: fix is_active to not rely on SIGCHLD, since it seems to create race conditions that i don't understand --- lib/IO/Pty/Easy.pm | 8 ++++++-- 1 file 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; } # }}} -- cgit v1.2.3-54-g00ecf