Clozure Lisp CGI Programming

Discussion of Common Lisp

Clozure Lisp CGI Programming

Postby Hero Doug » Thu May 07, 2009 5:00 am

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.
Hero Doug
 
Posts: 10
Joined: Thu May 07, 2009 4:52 am

Re: Clozure Lisp CGI Programming

Postby methusala » Thu May 07, 2009 1:55 pm

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.
methusala
 
Posts: 35
Joined: Fri Oct 03, 2008 6:35 pm

Re: Clozure Lisp CGI Programming

Postby Hero Doug » Fri May 08, 2009 10:42 pm

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?
Hero Doug
 
Posts: 10
Joined: Thu May 07, 2009 4:52 am

Re: Clozure Lisp CGI Programming

Postby cgsullivan » Sat May 09, 2009 7:11 pm

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?
cgsullivan
 
Posts: 2
Joined: Fri Dec 12, 2008 8:18 pm

Re: Clozure Lisp CGI Programming

Postby nuntius » Sun May 10, 2009 3:03 am

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
User avatar
nuntius
 
Posts: 498
Joined: Sat Aug 09, 2008 10:44 am
Location: Burlington, MA

Re: Clozure Lisp CGI Programming

Postby Wodin » Sun May 10, 2009 12:05 pm

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.
Wodin
 
Posts: 56
Joined: Sun Jun 29, 2008 8:16 am

Re: Clozure Lisp CGI Programming

Postby Hero Doug » Sun May 10, 2009 6:58 pm

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.
Hero Doug
 
Posts: 10
Joined: Thu May 07, 2009 4:52 am

Re: Clozure Lisp CGI Programming

Postby nuntius » Mon May 11, 2009 5:56 am

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.
User avatar
nuntius
 
Posts: 498
Joined: Sat Aug 09, 2008 10:44 am
Location: Burlington, MA

Re: Clozure Lisp CGI Programming

Postby Wodin » Mon May 11, 2009 11:30 am

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 :-)
Wodin
 
Posts: 56
Joined: Sun Jun 29, 2008 8:16 am

Re: Clozure Lisp CGI Programming

Postby cgsullivan » Mon May 11, 2009 4:35 pm

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.
cgsullivan
 
Posts: 2
Joined: Fri Dec 12, 2008 8:18 pm

Next

Return to Common Lisp

Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests

cron