cgi.lsp hanging while reading from stdin

For the Compleat Fan
Locked
cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

cgi.lsp hanging while reading from stdin

Post by 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:

Code: Select all

(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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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:

Code: Select all

#!/usr/bin/newlisp

(load "cgi.lsp")

(print  "Content-type: text/html\r\n\r\n")
(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.

Locked