[gambit-list] Difficulty with Gambit - Apache SELinux

Marc Feeley feeley at iro.umontreal.ca
Tue Feb 12 13:33:51 EST 2013


Wow... that's a really thorough analysis!

Let me just add that the error message "*** ERROR -- Unbound variable: main" can be avoided by

1) adding a (define (main) 0)
2) adding a (exit)
3) removing the name "gsi" from the shebang line, for example:  #! -:d-

Marc

On 2013-02-12, at 3:04 AM, Fred Weigel <fred_weigel at hotmail.com> wrote:

> Eduardo Costa <edu500ac <at> gmail.com> writes:
> 
>> 
>> 
>> One year or so ago, I contacted this list about running Gambit on
> Linux (I
>> compiled the programs on Zorin/Ubuntu, and tried to run them on a
> choice of
>> Linux hosting services). My programs work perfectly well in about
> every
>> Scheme compiler, except Gambit.
> [snip]
>> Internal Server ErrorThe server encountered an internal error or
>> misconfiguration and was unable to complete your request.
> [snip]
> 
> I find this error very disturbing, and decided (for my own sanity) to
> drill down. I adopted Gambit-C as my primary programming environment
> around six months ago, because it integrates well with C, is very
> platform neutral(runs on iOS, Android, Unix, Linux, Windows, etc.), is
> performance oriented, and is actively supported. I had just been working
> with Gambit-C as its own web server, but didn't see why it couldn't be
> used under Apache as a CGI script. So, I decided to "tackle" this issue.
> My intention is to deploy Gambit-C with different interfaces: sockets
> or pipes, as an Apache CGI, as a stand-alone web service that Apache
> forwards to ("middleware"), and with a stand-alone GUI. I see no reason
> why the Apache CGI isn't working for you, except for mis-configured
> Apache or Linux security.
> 
> I have tried to isolate the deployment of a compiled Gambit-C
> application into 3 main steps:
> 
> - deploy a simple BASH script
> - deploy Gambit-C interpreted (gsi) script
> - deploy compiled Gambit-C application
> 
> I do not go into Apache configuration; only if the simple BASH script
> doesn't work do we need to consider this.
> 
> The error (I am presuming code 500) can come from a variety of things.
> 
> Check the Apache logs (typically /var/log/httpd/error_log). If using
> SELinux some additional things need to happen (assuming you are copying
> your script to /var/www/cgi-bin). I would start with a simple "Hello,
> world" shell script -
> 
> #!/bin/bash
> # Make sure there is an empty line after Content-type
> echo "Content-type: text/html"
> echo
> echo "Hello, world"
> 
> You seem to have this covered; but look at the LACK of markup in the
> sample! Check the error_log, and if (as I suspect) it isn't executable:
> 
> Apache runs scripts as "nobody" or "apache":
> 
> # optional ownership change
> chown apache:apache cgi.sh
> # make sure everybody can execute
> chmod a+x cgi.sh
> 
> If it still complains (please look at error_log), you may need some
> SELinux kung-fu:
> 
> # Allow Apache to execute scripts
> # Only need to do this once...
> setsebool -P httpd_enable_cgi 1
> 
> # Restore httpd_sys_script_exec_t context to cgi.sh
> # (if the file was copied in from elsewhere...)
> cd /var/www/cgi-bin
> restorecon cgi.sh
> 
> (commands may be in /sbin)
> 
> Now, try the cgi.sh script: http://localhost/cgi-bin/cgi.sh
> This shoud work, and give you a "Hello, World". If not, post error_log,
> etc. We may need to dig into Apache configuration, but these
> instructions should cover RHEL (and derivative) OSs.
> 
> If cgi.sh works, we can go to the next step:
> 
> cp cgi.sh cgi.scm
> 
> (which copies the SELinux context as well) and make it a Gambit-C file:
> 
> #!/usr/bin/gsi
> (display "Content-type: text/html")
> (newline)
> (newline)
> (display "Hello, World from gsi")
> (newline)
> 
> and that is pretty much all there is to it! (for recent RHEL and Fedora
> with SELinux enforcing). Note the utter lack of tags -- keep it simple.
> 
> and, of course, test by browsing to http://localhost/cgi-bin/cgi.scm
> 
> Hello, World from gsi
> 
> The final step is compiling the script:
> 
> gsc -exe cgi.scm
> 
> (but add -:d- to the shebang line first)
> 
> Since "cgi" was compiled IN the correct directory, it should be SELinux
> tagged correctly. If it was compiled "out of directory", you will need:
> 
> restorecon -v cgi
> 
> And test with http://localhost/cgi-bin/cgi
> 
> Hello, World from gsi *** ERROR -- Unbound variable: main 
> 
> Now, if you leave off the -:d-, you will see it in the apache error_log:
> 
> [Mon Feb 11 22:48:38 2013] [error] [client 127.0.0.1]
> *** FATAL ERROR -- No controlling terminal (try using the -:d- runtime
> option)
> [Mon Feb 11 22:48:38 2013] [error] [client 127.0.0.1]
> Premature end of script headers: cgi
> 
> If you still have problems:
> 
> [fred at dejah cgi-bin]$ ldd cgi
> linux-vdso.so.1 =>  (0x00007fff1697b000)
> libutil.so.1 => /lib64/libutil.so.1 (0x0000003694000000)
> libdl.so.2 => /lib64/libdl.so.2 (0x0000003ebc000000)
> libm.so.6 => /lib64/libm.so.6 (0x0000003687000000)
> libc.so.6 => /lib64/libc.so.6 (0x0000003686000000)
> /lib64/ld-linux-x86-64.so.2 (0x0000003685c00000)
> 
> Hopefully, you are statically linking libgambc.a (cgi will be 5mb or
> so). If more performance is needed, we can deal with that. Running the
> cgi binary manually should also work!
> 
> [fred at dejah cgi-bin]$ ./cgi
> Content-type: text/html
> 
> Hello, World from gsi
> *** ERROR -- Unbound variable: main
> [fred at dejah cgi-bin]$ 
> 
> Now, I don't know how running with the Gambit-C library as a shared
> ".so" would work (haven't tried, but it should be pretty much the same),
> because I use the gsc that is supplied with my OS.
> 
> What I find remarkable is that the "other" Scheme implementations
> actually worked.
> 
> Fred Weigel
> 
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list




More information about the Gambit-list mailing list