Fix for closing fds with --background
Tomas Doran [Fri, 2 Mar 2012 20:23:07 +0000 (20:23 +0000)]
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.

Changes
lib/Catalyst/Script/Server.pm
t/author/podcoverage.t

diff --git a/Changes b/Changes
index 6320309..4a449a4 100644 (file)
--- 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
 
index 4e87191..799ec43 100644 (file)
@@ -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);
     }
 }
 
index 2875c7d..bee250c 100644 (file)
@@ -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$/;