Solved

C CGI Program system call problem

Posted on 1997-08-29
4
196 Views
Last Modified: 2013-12-25
I have a problem with my C cgi program on my NCSA HTTPD v1.5.
THe code look like:
fail = system("the_program_need_to_be_executed 1>/dev/null 2>/dev/null");
printf("show the fail value %d<P>",fail);
if (!fail)
        ............;

else
        ............;

The system call will return 0 if it is successful.
If I ran it from command line, it takes less then 1 sec to finish it.
When I ran it from the browser, it does not print the line.  THe browser seems
to wait for a long time.  I check the process status, the fork child processes
still sittng there.  How can I solve the problem and how can I trap it?

Thank you


                                                                     
                                                         
0
Comment
Question by:kuang
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
Philippe earned 100 total points
ID: 1829956

When you run the script from the prompt, it is run with your uid. The server probably runs with uid 'nobody'. Could that be your problem?

If not, you'll have to be more specific: Does the cgi work at all? Say, does it work if your remove the line 'fail=system...'?
Also, try piping stdout and stderr into a file (eg /tmp/debug) and tell us what you see.

 cheers,

   Philippe


0
 

Author Comment

by:kuang
ID: 1829957
I did ran a test(non cgi) as nobody(web uid).  it works.
I did run that cgi program and try to pipe the stdout and stderr to files which have been generateed but nothing in side the files.

If I comment the system call out it ran ok.

is there anything I can try further?

Thank you

0
 
LVL 84

Expert Comment

by:ozo
ID: 1829958
Could path be set differently when you run as nobody and
when the server runs your program?
Did you try specifying the full pathname to the_program_need_to_be_executed?

0
 
LVL 2

Expert Comment

by:Philippe
ID: 1829959

Kuang,

so we have a program which generates no output, works fine when you run it from prompt and blocks without givin an error message when run from the server.

Did you try ozo's comment? To have the same environment as nobody
would have ,try a 'su - nobody' (the '-' says that you also want to change the environment). You should then be in exactly the same situation as the browser.

Is there any chance that the machine on which you test your script and the machine on which the server runs are not the same?

What does your program actually do? Is it a script or a program you wrote. Does it access any remote files or do something it could need permission for? If you have access to the source of that program you could have it print out some debug information.

We might be able to help you more if you tell us more about that program.

  cheers,

   Philippe

0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now