LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Error - Premature end of script headers for C CGI Files (https://www.linuxquestions.org/questions/linux-newbie-8/error-premature-end-of-script-headers-for-c-cgi-files-725866/)

pramod.srk 05-14-2009 02:48 AM

Error - Premature end of script headers for C CGI Files
 
Dear All,
We are migrating an application from UNIX to RHEL-5.
I am getting following error:
"Premature end of script headers : : date.cgi

date.cgi is an executable with source written in C Lang.

Can anybody help me to resolve this error.

Thanks in Advance.


With Regards
Pramod

bathory 05-14-2009 04:25 AM

I guess you get the error from a webserver. You can check the webserver's error log for hints and also try to run the cgi from CLI and see if it produces valid HTML.
Most likely you'll need the sources to recompile it for linux.

Regards

pramod.srk 05-14-2009 04:44 AM

Thanks for the reply..

I got this error in the error log file of apache server.

I recompiled the file in RHEL-5.

The date.cgi accepts the date and time format as parameters through http and then creates an image of date using fly (which already installed).

The tool to test date.cgi using html is as follows

<html><body background="NA02.GIF">
date test<br>
<img src=today "date.cgi?mode=date&b1=255&b2=255&b3=255&s1=0&s2=0&s3=0&tp=bg">
</body></html>


The GIF file is present in the same directory where date.cgi resides.

bathory 05-14-2009 05:00 AM

What happens if you run the script directly in CLI:
Code:

/path/to/apache-cgi-bin/date.cgi?mode=date&b1=255&b2=255&b3=255&s1=0&s2=0&s3=0&tp=bg
Could be a permissions problem, if the cgi cannot create the image in the specified directory.

pramod.srk 05-14-2009 05:18 AM

I have given the permission 755 and tried even 777 as well to the directory and file.
But giving the same problem.

bathory 05-14-2009 05:37 AM

755 is generally OK, but in your case since you use RHEL it might be a SELinux problem, preventing the cgi to run correctly. That's why I'm telling you to run it from command line and see what it outputs. Better yet, run it as the user running apache.

pramod.srk 05-14-2009 06:36 AM

I ran date.cgi as follows with apache user
$./date.cgi "mode=date&b1=255&b2=255&b3=255&s1=0&s2=0&s3=0&tp=bg"

and I got nothing.

Do you have any idea about how to debug.
I tried by running gdb , but got null value for "getenv("REQUEST_METHOD")" and program exited.

bathory 05-14-2009 06:47 AM

You should run it exactly as it is requested by the browser:
Code:

./date.cgi?mode=date&b1=255&b2=255&b3=255&s1=0&s2=0&s3=0&tp=bg
Btw on what Unix was this cgi first running?

pramod.srk 05-14-2009 07:07 AM

It gives the the error as follows
[root@odn235 src]# ./date.cgi?mode=date&b1=255&b2=255&b3=255&s1=0&s2=0&s3=0&tp=bg&
[8] 2506
[9] 2507
[10] 2508
[11] 2509
[12] 2510
[13] 2511
-bash: ./date.cgi?mode=date: No such file or directory

The CGI's were running on HP - UNIX 32 bit machine.

The current machine is also RHEL-32 bit machine.

bathory 05-14-2009 07:38 AM

It should be better run it as the apache user. Most likely it cannot find the directory to write the image or something like that. Are you sure it's not a SELinux problem?
Could you post the code here, so someone familiar with C more than me could help?


All times are GMT -5. The time now is 04:30 AM.