Skip to content

Instantly share code, notes, and snippets.

@hinrik
Created June 22, 2010 18:58
Show Gist options
  • Save hinrik/448898 to your computer and use it in GitHub Desktop.
Save hinrik/448898 to your computer and use it in GitHub Desktop.
From 780e2410506ecd78b43c71ee2d2bbbc2a37184ca Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hinrik=20=C3=96rn=20Sigur=C3=B0sson?= <[email protected]>
Date: Tue, 22 Jun 2010 18:53:42 +0000
Subject: [PATCH] Fix child exit problems
A typo was plaguing the Program => ARRAY form.
Wrap the Program => CODE form in an eval. Otherwise, code that die()s
will not exit cleanly.
---
poe/lib/POE/Wheel/Run.pm | 16 +++++++++++-----
1 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/poe/lib/POE/Wheel/Run.pm b/poe/lib/POE/Wheel/Run.pm
index ffca736..91b26c3 100644
--- a/poe/lib/POE/Wheel/Run.pm
+++ b/poe/lib/POE/Wheel/Run.pm
@@ -427,17 +427,23 @@ sub new {
# TODO what if the program tries to exit? It needs to use
# our _exit_child_any_way_we_can handler...
- # Should we replace CORE::exit? CORE::die too? blahhhhhh
+ # Should we replace CORE::exit? blahhhhhh
# We've documented that users should not do it, but who knows!
- # Also, exceptions would screw this up - should it be eval'd?
- $program->(@$prog_args);
+ eval { $program->(@$prog_args) };
+
+ my $exitval;
+ if ($@) {
+ chomp $@;
+ warn $@, "\n";
+ $exitval = -1;
+ }
# Try to force stdio flushing.
close STDIN if defined fileno(STDIN); # Voodoo?
close STDOUT if defined fileno(STDOUT);
close STDERR if defined fileno(STDERR);
- __PACKAGE__->_exit_child_any_way_we_can();
+ __PACKAGE__->_exit_child_any_way_we_can((defined $exitval ? $exitval : ()));
}
# Execute an external program. This gets weird.
@@ -461,7 +467,7 @@ sub new {
# exec(SCALAR)
exec(join(" ", $program, @$prog_args))
- or __PACKAGE__->warn_and_exit_child(
+ or __PACKAGE__->_warn_and_exit_child(
"can't exec ($program) in child pid $$: $!", int( $! ) );
}
--
1.7.0.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment