Page 1 of 2

Clozure Lisp CGI Programming

Posted: Thu May 07, 2009 5:00 am
by Hero Doug
I'm attempting to set up CLozure CL for CGI programming and have run into a snag.

I can run the program perfectly from the command line, but it won't run through the browser. To make sure that the webserver was properly configured I wrote a simple hello world app in C and ran that through the cgi interface and it worked.

Here is the program.

Code: Select all

(defun test()
  (format t "Content-type: text/html~%~%")
  (format t "this is a test"))

(ccl:save-application "index.cgi" :toplevel-function #'test :prepend-kernel t)
Like I said everything works fine until it's run in apache. Here is the error log,
Couldn't load lisp heap image from
[Fri May 08 10:51:21 2009] [error] [client 127.0.0.1] Premature end of script headers: index.cgi
Why would the image load properly from the terminal but not from the browser? Permission issues? I ran Opera as root and had the same problem.

Thanks for any help.

Re: Clozure Lisp CGI Programming

Posted: Thu May 07, 2009 1:55 pm
by methusala
Try switching to the apache user and running the lisp program to see what the error is. You could also run the lisp program from a batch file, and redirect the error output to a file.

Re: Clozure Lisp CGI Programming

Posted: Fri May 08, 2009 10:42 pm
by Hero Doug
I gave full permissions to apache (www-data in Ubuntu) and I still have the same problem.

I think that it's highly unlikely that it's a permission problem because I compiled an equivalent C program and ran it without a hitch. I applied the same permissions from the C program to the lisp program and ran it and had the same problem.

I'm going to try compiling it without preprepending the kernel and see if I can load the image that way.

Any further ideas?

Re: Clozure Lisp CGI Programming

Posted: Sat May 09, 2009 7:11 pm
by cgsullivan
I just tried your example with Ubuntu 8.04 (32-bit), Apache2, ccl 1.3, and it worked for me as it should...

If you build the executable with the Lisp source file, lx86cl, and lx86cl.image all in the same directory, does it build the image file differently?

Re: Clozure Lisp CGI Programming

Posted: Sun May 10, 2009 3:03 am
by nuntius
Try loading a simple shell script as your CGI process:

cat <<_EOF > test.sh
#!/bin/sh

echo 'Content-type: text/html'
echo
echo
ulimit -a
_EOF

[The lines between _EOF go in the file test.sh]

I'm wondering whether apache hasn't set a the memory limits too small for clozure. If so, there should apache config settings (e.g. in httpd.conf or cgi.conf) to control this. Otherwise, you might also try asking on the clozure mailing lists or IRC.
http://trac.clozure.com/openmcl/wiki/WikiStart#Support

Re: Clozure Lisp CGI Programming

Posted: Sun May 10, 2009 12:05 pm
by Wodin
Hero Doug wrote:Why would the image load properly from the terminal but not from the browser? Permission issues? I ran Opera as root and had the same problem.
Hi

Running Opera as root is as likely to help as is wearing your lucky rocket-ship underwear ;-)

i.e., it's not Opera that is having trouble. It is Apache.

Re: Clozure Lisp CGI Programming

Posted: Sun May 10, 2009 6:58 pm
by Hero Doug
No, I ran it as Opera to see if the root user also had the same problems. I assumed (I'm not a Linux expert yet) that since root has full control over the system that any permission problems my regular account were having wouldn't apply to the root user. However, since the root user it getting Apache to do the work I guess it was a futile test.

Also, here is the result of the shell script.
time(seconds) unlimited
file(blocks) unlimited
data(kbytes) unlimited
stack(kbytes) 8192
coredump(blocks) 0
memory(kbytes) unlimited
locked memory(kbytes) 64
process unlimited
nofiles 1024
vmemory(kbytes) unlimited
locks unlimited
P.S. As a side note, SBCL is working fine. So maybe is has to do with the amount of memory CCL is requesting.

Re: Clozure Lisp CGI Programming

Posted: Mon May 11, 2009 5:56 am
by nuntius
Those limits don't look particularly restrictive. They probably match what you get by typing "ulimit -a" at a normal shell prompt. If so, this isn't your problem. If not, "ulimit -s 8192" and then starting ccl from the same shell should reproduce the problem separately from apache.

Re: Clozure Lisp CGI Programming

Posted: Mon May 11, 2009 11:30 am
by Wodin
Hero Doug wrote:No, I ran it as Opera to see if the root user also had the same problems. I assumed (I'm not a Linux expert yet) that since root has full control over the system that any permission problems my regular account were having wouldn't apply to the root user.
My point is that this is a CGI script that is running on a web server, right? The browser could be on any machine, including, e.g., a Windows machine that does not have a user called "root". So running Opera as root is irrelevant.
Hero Doug wrote:However, since the root user it getting Apache to do the work I guess it was a futile test.
Yes, except most Linux distributions do not run Apache as root. As you mentioned, Ubuntu uses the www-data user for Apache.

Unless you can get more detailed error messages out of Apache it could be something to do with www-data not having access to all the bits of ccl that are needed in order to run your program. This does seem unlikely given that you (presumably as a normal user) can run it from the command line.
Hero Doug wrote:I think that it's highly unlikely that it's a permission problem because I compiled an equivalent C program and ran it without a hitch. I applied the same permissions from the C program to the lisp program and ran it and had the same problem.
There's a difference, though. The C program is more or less self contained. It will most likely depend on the C library, but if there were permission problems with that you would have more problems than just your CGI program. Your lisp program might depend on other bits of CCL that Apache is having trouble finding or does not have access to. (I've never used CCL, so I'm not sure of the details.)

CCL does not appear to be in the Ubuntu repositories, so I suppose you installed it manually, whereas sbcl was installed from the repositories? This could hint at why sbcl works and ccl doesn't.

I hope this helps :-)

Re: Clozure Lisp CGI Programming

Posted: Mon May 11, 2009 4:35 pm
by cgsullivan
Hmm... I responded Friday, but due to 1st post approval issues it is now in the middle of the pack and probably easy to skip.

It might not be an Apache issue. The error message you cite is interesting:

"Couldn't load lisp heap image from "

with it blank after 'from'. This error message is from within CCL's load_image():

http://svn.clozure.com/publicsvn/openmc ... l-kernel.c

Perhaps it's having problems sorting out the internal geography of its own executable. CCL does seem to have some quirks, hence the idea of rebuilding the image file with CCL & the source file in the same directory to see if it builds it slightly differently.

On a probably-not-related note, I encountered a similar sounding situation once where the issue was that the environment the task ran under in Apache was not the same as the environment from the shell prompt. Running a diagnostic dump of the environment under Apache & comparing it with the normal one highlighted the issue, and modifying Apache's environment solved the problem. In particular, I would try making sure that the PATH variable includes your cgi directory.

To be specific, creating some print-env.cgi

Code: Select all

#!/bin/sh

echo "Content-type: text/html"
echo ""
echo $PATH
might show something interesting. And under Ubuntu you could try adding something like this to /etc/apache2/envvars

Code: Select all

   export PATH=/usr/local/bin:/usr/bin:/bin:/home/test/cgi-bin 
Good luck! You've been admirably persistent.