Skip to content

Commit

Permalink
Prevent the signal pipe from being used during signal finalization
Browse files Browse the repository at this point in the history
Added a note about EIO in POE::Wheel::Run
  • Loading branch information
Philip Gwyn committed Sep 8, 2009
1 parent 0b222a7 commit 744d48f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/POE/Resource/Signals.pm
Expand Up @@ -168,10 +168,13 @@ sub _data_sig_get_safe_signals {
}

### End-run leak checking.
our $finalizing;

sub _data_sig_finalize {
my( $self ) = @_;
my $finalized_ok = 1;
# tell _data_sig_pipe_send to ignore CHLD that waitpid might provoke
local $finalizing = 1;

$self->_data_sig_pipe_finalize;

Expand Down Expand Up @@ -212,6 +215,7 @@ sub _data_sig_finalize {
local $?;

my $leaked_children = 0;

until ((my $pid = waitpid( -1, 0 )) == -1) {
_warn( "!!! Child process PID:$pid reaped: $!\n" ) if $pid;
$finalized_ok = 0;
Expand Down Expand Up @@ -771,7 +775,8 @@ sub _data_sig_pipe_finalize {
if( $signal_pipe_write ) {
close $signal_pipe_write; undef $signal_pipe_write;
}
undef $signal_pipe_pid;
# Don't send anything more!
undef( $signal_pipe_pid );
}

### Send a signal "message" to the main thread
Expand All @@ -784,10 +789,17 @@ sub _data_sig_pipe_send {
if( TRACE_SIGNALS ) {
_warn "<sg> Caught SIG$_[1] ($n)";
}

return if $finalizing;

if( not defined $signal_pipe_pid ) {
_trap "<sg> $$ _data_sig_pipe_send called before signal pipe was initilised.";
}
if( $$ != $signal_pipe_pid ) {
_trap "<sg> Kernel now running in a different process. You must call call \$poe_kernel->has_forked in the child process.";
_trap "<sg> Kernel now running in a different process (is=$$ was=$signal_pipe_pid). You must call call \$poe_kernel->has_forked in the child process.";
}


my $count = _data_sig_pipe_syswrite( pack( "C", $n ) );
if( ASSERT_DATA ) {
if( $count != 1 ) {
Expand Down
3 changes: 3 additions & 0 deletions lib/POE/Wheel/Run.pm
Expand Up @@ -1413,6 +1413,9 @@ A sample error event handler:
warn "Wheel $wheel_id generated $operation error $errnum: $errstr\n";
}
Note that unless you deactivate the signal pipe, you might allso see C<EIO>
(5) error during read operations.
=head4 StdinEvent
StdinEvent contains the name of an event that Wheel::Run emits
Expand Down

0 comments on commit 744d48f

Please sign in to comment.