gsa wrote:
> I have this cgi code that sometimes forks depending on the
>size of input. If there is an error, a subroutine called print_error
>is called and this subroutine prints an error message and dies. If the
>cgi forks and there is a child, then this error message is captured by
>an eval statement and is printed to the log file. However, if the cgi
>does not fork, there is an ugly software error message on the page. Is
>there a way to die so that when the cgi forks, eval captures the error
>message but at the same time there is no nasty software error when the
>cgi doesn't fork?
fork returns a child process id if it forks, so you can know if you're
in the parent or in the child. Store it in a variable. Simply let the
error handler behave differently depending on what's in that variable.
You may want to use a dummy value in that variable in case you skip
forking, and thus, you actually are in the parent.
--
Bart.
|