How to make a cgi program "die" without a software error messagebeing printed to page

G

gsa

Hi all,
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? I guess the easiest way is to turn CGI::Carp off but
is there another way to exit/die?

Thanks a lot!
Gayathri
 
B

Bart Lateur

gsa said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top