jwd
jwd

Reputation: 11114

Apache CGI - nonzero exit code

I have a CGI script that is generally working fine.

However, under certain circumstances it can fail, which results in a non-zero exit code. Sometimes, it will already have output the headers, etc before failing.

For instance, the output just might be:

Content-Type: text/html; charset=utf-8

<empty body>

Then with a program exit code of 123.

Currently, Apache treats this as HTTP 200 and happily returns a blank page to the user.

Is there some way to make Apache treat such a program failure as an error?

I actually had thought it would return HTTP 500 in such cases, but apparently I was wrong (or something is misconfigured).

Upvotes: 1

Views: 1040

Answers (1)

covener
covener

Reputation: 17871

There is no way to get mod_cgi/mod_cgid to buffer the status line / headers / body to make sure the CGI eventually exits successfully. Even with an empty body, it's too late since the status line is written as soon as the headers are terminated.

An enhancement to Apache aside, your CGI would have to buffer its own stdout, or you would have to wrap it in something that buffered all of the stdout and ran the CGI to completion.

Upvotes: 2

Related Questions