LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-25-2007, 07:46 PM   #1
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Rep: Reputation: 32
Angry GCC compiles, program runs, but only in a CERTAIN directory


Hello! I am having a serious problem when trying to make a CGI-script (which I've done many times before in the past), my program will only run in a CERTAIN folder, and do absolutely nothing in the cgi-scripts folder. For example, here is the output from my terminal:

Code:
[th317erd@TheNerd programs]$ gcc -o cgi-test cgi-test.c
[th317erd@TheNerd programs]$ ./cgi-test
Content-type: text/html

Hello world![th317erd@TheNerd programs]$ cp cgi-test /var/www/cgi-bin/
[th317erd@TheNerd programs]$ /var/www/cgi-bin/cgi-test
[th317erd@TheNerd programs]$
As you can see, it compiles fine, runs fine in the ~/programs directory, but as soon as I copy it to /var/www/cgi-bin (with permissions on var www and cgi-bin set to 777 for development on my own personal computer [I wouldn't set the server up like this]), the program doesn't run at all.

I am at a complete loss. Please help me.

I am running Fedora Core 3, 64bit version, on a AMD XP 64bit
proccessor

GCC version = g++ (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)
The apache server isn't running at the time I tried this test, I disabled it because I thought maybe (just maybe...) it might be causing this problem.
 
Old 03-25-2007, 09:51 PM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
I wouldn't say it doesn't run at all. It seems to run, but give no output. Otherwise, bash would tell you why it hadn't run.

Is the code small enough that you can post it?
 
Old 03-25-2007, 10:01 PM   #3
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Original Poster
Rep: Reputation: 32
I am sorry! I knew I forgot something:

Code:
#include <stdio.h>

int main(int argc, char **argv)
{
    printf("Content-type: text/html\n\n");
    printf("Hello world!");
}
I've even tried code that caused a direct crash (by index out of bounds), and it didn't crash, it just did nothing at all.
 
Old 03-26-2007, 12:37 AM   #4
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Does the program have execution permissions?

with the ./ it doesn't need it but by providing teh full path you should add that the program can be executed.
 
Old 03-26-2007, 12:39 AM   #5
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Original Poster
Rep: Reputation: 32
Yes, it does. I made sure by setting the mode of the file to 777.
 
Old 03-26-2007, 01:03 AM   #6
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
What happens when you move to the cgi-bin directory and try and execute it with a ./cgi-test?
Do you have SELinux running?
 
Old 03-26-2007, 01:06 AM   #7
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Original Poster
Rep: Reputation: 32
I do not think that I have SELinux running (I remember turning it off sometime in the past), but, honestly, I don't know how to check. I'll try moving the directory and let you know what happens.
 
Old 03-26-2007, 01:42 AM   #8
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Is /var/www/cgi-bin located on a separate partition/filesystem?

If so, check /etc/fstab. See if the "noexec" option is set for that partition.
 
Old 03-26-2007, 02:37 AM   #9
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Original Poster
Rep: Reputation: 32
No, /var/www/cgi-bin is NOT a separate file system

I've tried a few different things, and... it is strange.
1) /var/www and /var/www/cgi-bin are the ONLY folders that it WONT run in (I haven't tested /var)
2) If MOVE cgi-bin to my home folder, and RECOPY it into ~/cgi-bin, it still wont run.
3) If I MOVE the executable FROM cgi-bin TO ~/, then it wont run.
4) If I REMOVE ~/cgi-test and the RECOPY it from ~/programs TO ~/, then it runs fine.
5) If I REMOVE it from cgi-bin, and recopy it from ~/programs to cgi-bin, then it still wont work.
6) If I delete cgi-bin, and remake it (plus recopy cgi-test to it), then IF CGI-BIN IS IN /var/www
it wont run.

Code:
[th317erd@TheNerd www]$ cd
[th317erd@TheNerd ~]$ ./cgi-test
Content-type: text/html

Hello world![th317erd@TheNerd ~]$ cp ./cgi-test /var/www/cgi-bin/
[th317erd@TheNerd ~]$ cd /var/www/cgi-bin/
[th317erd@TheNerd cgi-bin]$ ls -l
total 12
-rwxrwxr-x  1 th317erd th317erd 6855 Mar 25 23:27 cgi-test
[th317erd@TheNerd cgi-bin]$ ./cgi-test
[th317erd@TheNerd cgi-bin]$ cd ..
[th317erd@TheNerd www]$ ls -l
total 256
(### other entries omitted for clarity)
drwxrwxrwx   2 th317erd  th317erd  4096 Mar 25 23:27 cgi-bin
(### other entries omitted for clarity)
[th317erd@TheNerd www]$ rm -fr cgi-bin
[th317erd@TheNerd www]$ mkdir cgi-bin
[th317erd@TheNerd www]$ cp ~/cgi-test /var/www/cgi-bin/
[th317erd@TheNerd www]$ cd cgi-bin/
[th317erd@TheNerd cgi-bin]$ ./cgi-test
[th317erd@TheNerd cgi-bin]$ cd ..
[th317erd@TheNerd www]$ ls -l
total 256
(### other entries omitted for clarity)
drwxrwxr-x   2 th317erd  th317erd  4096 Mar 25 23:28 cgi-bin
(### other entries omitted for clarity)
What the heck is going on? I think it is a permissions problem, but where and what?
 
Old 03-26-2007, 03:06 AM   #10
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,287

Rep: Reputation: 173Reputation: 173
change the executable file extention to .cgi
 
Old 03-26-2007, 03:10 AM   #11
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by bigearsbilly
change the executable file extention to .cgi
That didn't help at all, but thanks anyhow.
 
Old 03-26-2007, 03:21 AM   #12
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,287

Rep: Reputation: 173Reputation: 173
what about apache error logs?

?? /var/logs/apache/error_log
or something?


do a tail -f on it while you try the CGI script.
 
Old 03-26-2007, 03:25 AM   #13
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,287

Rep: Reputation: 173Reputation: 173
have you got CGI enabled in apache.conf files.
does any script work?


browser to http://localhost/manual and follow the instructions

Last edited by bigearsbilly; 03-26-2007 at 03:27 AM.
 
Old 03-26-2007, 03:37 AM   #14
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by bigearsbilly
have you got CGI enabled in apache.conf files.
does any script work?


browser to http://localhost/manual and follow the instructions
I don't think you relise, like I said in previous posts, that I have apache disabled. I am simply trying to run the CGI executable from the BASH shell.
 
Old 03-26-2007, 03:48 AM   #15
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,287

Rep: Reputation: 173Reputation: 173
aah sorry...


as previously suggested

Quote:
If so, check /etc/fstab. See if the "noexec" option is set for that partition.
post your /etc/fstab if in doubt
 
  


Reply

Tags
executable, running


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
g++ compiles but not gcc senthilpr_in Linux - Software 10 08-29-2005 02:20 PM
C code compiles on windows, but not with gcc MDBlueIce Programming 6 05-23-2005 04:33 PM
gcc, segmentation fault, though compiles... scratch09 Programming 5 11-20-2004 05:11 PM
Java, code compiles and supposedly runs fine in windows, but not linux exodist Programming 4 03-16-2004 12:47 PM
RedHat 9.0, Kernel 2.4.21, Linux-Wlan-Ng-0.2.1, Compiles and Runs. But Cant Connect. AndrewBalmos Linux - Wireless Networking 5 01-18-2004 06:18 PM


All times are GMT -5. The time now is 03:46 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration