From: Tomas Doran Date: Fri, 2 Mar 2012 20:23:07 +0000 (+0000) Subject: Fix for closing fds with --background X-Git-Tag: 5.90011~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=df894348b6f8e0bea1b3d0576aad28027ee930df Fix for closing fds with --background As web load the app (and therefore setup file loggers) before we use MX::Daemonize, it's closing stuff clobbers everything. Therefore we just close STDIN/STDOUT/STDERR, leaving anything the user has setup. --- diff --git a/Changes b/Changes index 6320309..4a449a4 100644 --- a/Changes +++ b/Changes @@ -10,6 +10,9 @@ their test suites. - Bug fix to again correctly detect checkouts in dist zilla using applications. + - --background option for the server script now only closes + STDIN, STDOUT and STDERR. This fixes issues with Log::Dispatch + and other loggers which open a file handle when 5.90010 - 2012-02-18 00:01:00 diff --git a/lib/Catalyst/Script/Server.pm b/lib/Catalyst/Script/Server.pm index 4e87191..799ec43 100644 --- a/lib/Catalyst/Script/Server.pm +++ b/lib/Catalyst/Script/Server.pm @@ -71,17 +71,20 @@ has pidfile => ( predicate => '_has_pidfile', ); +# Override MooseX::Daemonize +sub dont_close_all_files { 1 } sub BUILD { my $self = shift; if ($self->background) { # FIXME - This is evil. Should we just add MX::Daemonize to the deps? - try { Class::MOP::load_class('MooseX::Daemonize::Core') } + try { Class::MOP::load_class('MooseX::Daemonize::Core'); Class::MOP::load_class('POSIX') } catch { warn("MooseX::Daemonize is needed for the --background option\n"); exit 1; }; MooseX::Daemonize::Core->meta->apply($self); + POSIX::close($_) foreach (0..2); } } diff --git a/t/author/podcoverage.t b/t/author/podcoverage.t index 2875c7d..bee250c 100644 --- a/t/author/podcoverage.t +++ b/t/author/podcoverage.t @@ -8,7 +8,7 @@ use Test::Pod::Coverage 1.04; my @modules = all_modules; our @private = ( 'BUILD' ); foreach my $module (@modules) { - local @private = (@private, 'run') if $module =~ /^Catalyst::Script::/; + local @private = (@private, 'run', 'dont_close_all_files') if $module =~ /^Catalyst::Script::/; local @private = (@private, 'plugin') if $module =~ /^Catalyst$/; local @private = (@private, 'snippets') if $module =~ /^Catalyst::Request$/; local @private = (@private, 'prepare_connection') if $module =~ /^Catalyst::Engine$/;