Httpd, cgi shell scripts not working
Denys Vlasenko
vda.linux at googlemail.com
Fri Sep 18 20:07:03 UTC 2009
On Friday 18 September 2009 18:30, Leonid Lisovskiy wrote:
> >I'm having a problem getting httpd to run shell scripts - they just return
> >empty screens.
>
> Answer is simple - you have to read documentation first ;-)
>
> Since some version, busybox's httpd expects that you are responsible
> for generating HTTP headers inside shell script. I.e. you have to do
> like this:
>
> echo "HTTP/1.0 200 OK
> Content-type: image/png
> Connection: close
> "
No. You do not _have to_ output it, it's optional.
httpd will supply "HTTP/1.0 200 OK" if it is not supplied
by the CGI. Here is the relevant code from httpd.c:
} else if (out_cnt >= 4) {
/* Did CGI add "HTTP"? */
if (memcmp(rbuf, HTTP_200, 4) != 0) {
/* there is no "HTTP", do it ourself */
if (full_write(STDOUT_FILENO, HTTP_200, sizeof(HTTP_200)-1) != sizeof(HTTP_200)-1)
break;
}
But you _have to_ output at least the one empty
line, to signify end of header.
Here's the doc:
http://hoohoo.ncsa.illinois.edu/cgi/out.html
Parsed headers
The output of scripts begins with a small header.
This header consists of text lines, in the same format as an HTTP header,
terminated by a blank line (a line with only a linefeed or CR/LF).
IOW:
printf "\r\nMinimal CGI example"
--
vda
More information about the busybox
mailing list