[Catalyst] system() within Catalyst

Brian Kirkbride brian.kirkbride at deeperbydesign.com
Thu Oct 19 04:25:58 CEST 2006


Brandon Maust wrote:
> Hi. 
> 
> I'm trying to use Chart::Graph::Gnuplot to generate some images inside 
> of one of my application's Views.  That module uses system() to run 
> gnuplot and checks the return status like so, as described in the 
> system() documentation:
> 
>     $exit_value  = $? >> 8;
>     $signal_num  = $? & 127;
>     $dumped_core = $? & 128;
> 
> 
> My problem is that while gnuplot (and several other commands such as 
> touch and cat) seem to run successfully, perl sees a non-zero exit code 
> within Catalyst.  Running the same code in a straight perl script 
> provides the expected results.
> 
> Is this a known effect?  Aside from editing the source for this module, 
> I can't find a good workaround to use it.
> 
> Thanks for any suggestions,
> Brandon
> 

This is a known issue when running under the dev HTTP server included with 
Catalyst.   My solution has been to wrap the system() call inside a block with a 
default SIGCHLD handler like so:

{
	local $SIG{CHLD} = 'DEFAULT';
	system(@args);
	if ($?) {
		die "Failed: $?\n";
	}
}

This is related to the Restarter code in Catalyst::Engine::HTTP.  I had started 
to see if the signal handler could be reset to the default in the forked child 
process to avoid this problem, but didn't have the time to fix it.  I only use 
system() in 1 or 2 places and the local fix was acceptable for me.

Best,
Brian Kirkbride



More information about the Catalyst mailing list