cgi.lsp hanging while reading from stdin

Started by cormullion, September 23, 2007, 03:46:05 PM

Previous topic - Next topic

cormullion

I don't really know much about this subject, so please forgive me if I'm talking rubbish.



I'm been having problems getting a newlisp cgi script to run (using Apache on FreeBSD, I think). When the cgi.lsp runs, it seems to do a  (set 'inline (read-line)). This means that it waits for input, doesn't it? And the script was hanging waiting for stdin input.



Anyway, someone suggested "Why don't you check the proper environment variable to see if it's a POST request first? Then if it was a GET, you wouldn't hang reading data from STDIN." A quick bypass like this got basic cgi operations working:


(if (!= params nil)
  (begin
  (set 'inline (read-line))
  (if inline
    (set 'params (get-vars inline)))))


However, this appears to prevent any POST requests from getting through.



So, how to avoid waiting for read-line yet get any POST requests that are waiting?



Does any of this make sense? :-)

Lutz

#1
In a webserver setup stdin will not block, but 'read-line' will return 'nil' when no stdin is present.



Try the following file for a simple start, to write CGI files in newLISP:


#!/usr/bin/newlisp

(load "cgi.lsp")

(print  "Content-type: text/htmlrnrn")
(println "<h2>Hello World</h2>")
(exit)


give your file a .cgi extension and make sure you have 755 (-rwxr-xr-x) permissions on your cgi file and the correct owner and group membership. When the above file works, study the files in the newlisp-ide and newlisp-wiki applications for using the services of cgi.lsp.



Lutz



ps: all this assumes that Apache is set up correctly to allow cgi and in the directory where your cgi files reside.