[Catalyst] Re: System call problem

Florent Angly florent.angly at gmail.com
Wed Dec 24 13:41:31 GMT 2008


Hi t0m,

I wouldn't really call this a Catalyst bug. It's more some sort of Perl 
behavior that I did know of / expect. My Catalyst code is along these 
lines (and runs on a Linux 2.6 kernel):

sub catalyst_run_app {
      my $original_sig_chld = $SIG{CHLD}; # system calls always return 
-1 ("No child processes"), even when the call is sucessful
      $SIG{CHLD} = 'DEFAULT'; # system calls will return 0 for success 
(-1 is a failure)
      use 'App';
      eval {
         &App::main(); # This function contains a system() call
      };
      $SIG{CHLD} = $original_sig_chld; # restore original sig chld value
      if ($@) { # check for execution errors
        # warn that there was an execution error
      }
      # Display results
}

There's some more info about this at: 
http://www.schwer.us/journal/2008/02/06/perl-sigchld-ignore-system-and-you/
I must say that I don't fully appreciate the differences between the 
different child signal methods. I'm happy with using 'DEFAULT'.

The easiest way to reproduce this behavior is to run these commands:
  perl -e '$SIG{CHLD} = 'IGNORE'; print system('echo')."\n";'
Returns:
  -1
Whereas:
  perl -e '$SIG{CHLD} = 'DEFAULT'; print system('echo')."\n";'
Returns:
  0

I'm not sure what you mean with using $class->handle_request; in 
Catalyst/Engine/HTTP.pm. My Catayst app runs using the Catalyst test 
server at the moment. I haven't deployed it on a standalone webserver yet.

Cheers,

Florent



Tomas Doran wrote:
>
> On 19 Dec 2008, at 16:21, Florent Angly wrote:
>
>> Well, after some more fiddling and researching, I figured this 
>> problem out.
>> Using the modified command:
>>> system(@formatdb_cmd) == 0 or die("Could not run command: 
>>> @formatdb_cmd\nReturn status: $?\nMessage: $!");
>> I found out that my error message is:
>>> No child processes
>> It turns out that in Catalyst, $SIG{CHLD} = 'IGNORE'. Setting 
>> $SIG{CHLD} to 'DEFAULT' makes the system() calls return the proper 
>> status.
>
> I assume that you do this like this:
>
> {
>     local $SIG{CHLD} = 'DEFAULT';
>     system('my system command');
> }
>
> Does doing something similar around $class->handle_request; in 
> Catalyst/Engine/HTTP.pm make it work in a generic way so that you 
> don't have to do this hack locally?
>
> And is there any chance you could write a simple test which shows the 
> return values being lost, so that we can properly fix this in 
> Catalyst, with appropriate regression testing?
>
> Cheers
> t0m
>
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: 
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>




More information about the Catalyst mailing list