Problem serving executables with HTML out

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rohswell
    New Member
    • Feb 2008
    • 2

    #1

    Problem serving executables with HTML out

    When my Apache installation tries to serve an executable file (web page) it gives an internal server error. I have installed and setup Apache under Cygwin under Windows XP. I am writing web pages for an embedded Linux system and using the setup above as a development/test platform. Each web page is a C program, compiled and linked to produce an executable using Cygwin and Gnu C. For example, the home page would be index.exe. When this program is executed on the Cygwin command line, it sends HTML to stdout that defines the web page. The HTML is valid per HTML 4.01 Transitional.

    I attempted to configure Apache to execute all web pages as CGI scripts. Here are the significant lines from httpd.conf:

    Code:
    ServerRoot "/tools/apache"
    DocumentRoot "/tools/apache/htdocs"
    <Directory "/tools/apache/htdocs">
        Options Indexes FollowSymLinks ExecCGI
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
    
    <IfModule alias_module>
        ScriptAlias /cgi-bin/ "/tools/apache/htdocs/"
    </IfModule>
    
    <IfModule mime_module>
        TypesConfig conf/mime.types
        AddType text/html .exe
        AddHandler cgi-script .exe
    </IfModule>
    Apache works and serves HTML pages, but will not serve index.exe in the htdocs folder. The URL http://192.168.0.101/index.exe produces an internal server error. The error log reads:
    [Tue Feb 05 09:02:56 2008] [error] [client 192.168.0.101] Premature end of script headers: index.exe

    The access log reads:
    192.168.0.101 - - [05/Feb/2008:09:02:56 -0700] "GET /index.exe HTTP/1.1" 500 535

    Again, I know that index.exe produces valid HTML out. If I redirect its output to a file, say home.htm, then Apache will serve that HTML file just fine.

    I guess I did something wrong in the config file, but I don't know what. I've read the documentation on the config parameters. I changed the ScriptAlias value from cgi-bin to htdocs because I want all the web pages in the main web folder, not in a separate place.

    This is where I really struggle trying to understand. Why would CGI scripts be placed in a folder outside the main web site anyway? I also write PHP web sites served on hosted machines and I don't have to create a special folder for the PHP files.

    Any help will be greatly appreciated. Thanks.
  • rohswell
    New Member
    • Feb 2008
    • 2

    #2
    Here's some new information.

    In the config file, I commented out everything in the Alias module and left the entries for mime types. Now Apache will serve .exe files, as long as they run to completion and produce text/html out.

    The problem has been narrowed to a call to shmget to access shared memory segments created by another process. Any CGI program using this shared memory method will run correctly if executed on the Cygwin command line. However, it always fails when Apache runs it.

    I tried changing User to rayf and Group to None to match what I see in Cygwin. But that had no affect. So the question becomes, what is it about the Apache process that causes shmget to fail? The error reported by Apache is still "Premature end of script headers" which now makes sense because I understand the header line "Content-type: text/html\n\n" is not being sent because index.exe dies in shmget before it generates output.

    Comment

    Working...