LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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-16-2005, 03:13 PM   #1
Godsmacker777
Member
 
Registered: Oct 2004
Posts: 52

Rep: Reputation: 15
basic linux programming/compiling question (permissions error)


Hey there,

I hate to ask such a seeming dumb question, but I can't seem to figure this one out. I am definitely new to C and programming in general, though I have been doing a bit on my ibook laptop over the past few months. In osx I usually write the code (I'm only using C right now) in xcode, then compile the c file from a terminal. I use these commands to compile and run the program.

Code:
cc xxx.c
./a.out
I want to do more work on my desktop (running Gentoo Linux, using the 2.6.10 kernel), so I tried compiling a stupid hello world kind of program to test it out. I tried the same method as I run in osx, though I get a permissions error. Here is what I do:

Code:
cc hello.c
./a.out
bash: ./a.out: Permission denied
The permissions look fine; I tried setting them to 770 and 777 just to be sure. I also tried these steps as root, as well as renaming the file.

What am I doing wrong?


Thanks
 
Old 03-16-2005, 03:16 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Interesting. Please show us how the permissions and ownership looks after you compile. Run:
ls -l a.out
and post the result.
 
Old 03-16-2005, 03:20 PM   #3
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
Not sure... is 'cc' the same as 'gcc' on your machine? (It is on my Gentoo box, but you never know.) Try using 'gcc' instead of 'cc', to see if that makes a difference. I'd also suggest giving an output filename, instead of using the default a.out, like so:

Code:
gcc -Wall hello.c -o hello
(The '-Wall' will print extra warnings and errors, which may help identify any possible bugs in the program.)

No clue if these things will help, but it's all I can think of. I hope it helps!
 
Old 03-16-2005, 04:28 PM   #4
Godsmacker777
Member
 
Registered: Oct 2004
Posts: 52

Original Poster
Rep: Reputation: 15
ok so to help you guys out and give a little more information...
I tried all of these things, but I will do it all again to try and paint the complete picture.

Code:
bash-2.05b# ls
hello.c

bash-2.05b# cc hello.c

bash-2.05b# ls -l
total 12
-rwx------  1 root  root  6926 Mar 16 17:22 a.out
-rw-------  1 jason users   88 Mar 16 16:51 hello.c

bash-2.05b# ./a.out
bash: ./a.out: Permission denied

bash-2.05b# mv a.out tryme

bash-2.05b# ./tryme 
bash: ./tryme: Permission denied

bash-2.05b# ls -l
total 12
-rw-------  1 jason users   88 Mar 16 16:51 hello.c
-rwx------  1 root  root  6926 Mar 16 17:22 tryme

bash-2.05b# chmod 777 tryme 

bash-2.05b# ls -l
total 12
-rw-------  1 jason users   88 Mar 16 16:51 hello.c
-rwxrwxrwx  1 root  root  6926 Mar 16 17:22 tryme

bash-2.05b# ./tryme 
bash: ./tryme: Permission denied

bash-2.05b# chown jason:users tryme 

bash-2.05b# ls -l
total 12
-rw-------  1 jason users   88 Mar 16 16:51 hello.c
-rwxrwxrwx  1 jason users 6926 Mar 16 17:22 tryme

bash-2.05b# ./tryme 
bash: ./tryme: Permission denied

bash-2.05b# exit
exit

bash-2.05b$ ./tryme 
bash: ./tryme: Permission denied

bash-2.05b$ gcc -Wall hello.c -o hello

bash-2.05b$ ls -l
total 20
-rwx------  1 jason users 6926 Mar 16 17:28 hello
-rw-------  1 jason users   88 Mar 16 16:51 hello.c
-rwxrwxrwx  1 jason users 6926 Mar 16 17:22 tryme

bash-2.05b$ ./hello 
bash: ./hello: Permission denied

bash-2.05b$ cat hello.c 
#include <stdio.h>

int main(void)
        {
        printf("\n\nWell I'll be damned, I got it to work...\n\n");
        return(0);
        }
This should work, and this is why I am so confused; I must be missing something.
 
Old 03-16-2005, 04:56 PM   #5
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
It may not be a compiler/program problem at all.

My guess: you're working in a partition that was mounted as noexec in fstab.
 
Old 03-16-2005, 05:47 PM   #6
Godsmacker777
Member
 
Registered: Oct 2004
Posts: 52

Original Poster
Rep: Reputation: 15
I read your reply and immediately felt stupid...one of those duh moments...

I am trying to do all of this on my home partition, so I then double checked fstab:

Code:
/dev/hda6  /home   reiserfs defaults,noatime,user,notail                    0 3
checking my fstab, only my ntfs partitions are mounted noexec. To be completely sure I copied the compiled file to /root/ and ran it as root. Viola....

so is my /home partition mounted noexec by default?

I appreciate your time, I am certainly needed another pair of eyes.
 
Old 03-16-2005, 07:31 PM   #7
gbonvehi
Senior Member
 
Registered: Jun 2004
Location: Argentina (SR, LP)
Distribution: Slackware
Posts: 3,145

Rep: Reputation: 53
Just two doubts, I don't think they'll matter, but why you've in the 6th parameter 3 when the choices (if i'm not wrong) are 0,1 or 2, and why you allow user to mount/umount the /home directory? (I think this doesn't matter because it's mounted by root, and as long as root don't umount it other users can't)
 
Old 03-16-2005, 11:16 PM   #8
Godsmacker777
Member
 
Registered: Oct 2004
Posts: 52

Original Poster
Rep: Reputation: 15
Now that you mention it, I think you are right in that it really doesn't matter; a regular won't need to unmount or mount it the /home partition. I am the only user at the computer so I set it up that my regular user would have access to things like that, though in this case it really doesn't matter.

So I copied the executable to /root/ and ran it just fine. Any ideas? Is /home/ mounted noexec despite my fstab options?
 
Old 03-17-2005, 12:16 AM   #9
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
I don't see anything in those options that would prevent execution, but I don't have much experience with reiserfs (translation: none). I might check your startup scripts to see if it gets remounted later with different options, and to make sure no other partition is being mounted "on top" of it. That's really just guessing though.

If you cat /etc/mtab, it might list what options each partition was mounted with. It seems to list them on my system (LFS), but the point of LFS is to be unique... yours could very well be different.
 
Old 03-17-2005, 04:27 AM   #10
gbonvehi
Senior Member
 
Registered: Jun 2004
Location: Argentina (SR, LP)
Distribution: Slackware
Posts: 3,145

Rep: Reputation: 53
[Edit] Stupid suggestion as you were trying to run it as root on your home folder.

Well, another posibility is with your user... can you run other programs inside your home directory?
Try creating another account and trying there.

Last edited by gbonvehi; 03-17-2005 at 04:33 AM.
 
Old 03-17-2005, 11:32 AM   #11
Godsmacker777
Member
 
Registered: Oct 2004
Posts: 52

Original Poster
Rep: Reputation: 15
from cat /etc/mtab:

Code:
/dev/hda6 /home reiserfs rw,noexec,nosuid,nodev,noatime,notail 0 0
Looks like there's the problem. I would like to find out who is mounting this with these options; where should I start my search? How come the options in fstab don't override all other mounting options (as it is user defined I would think that it would have precendece over everything else)

here is the relevent section of dmesg, I don't know if this will help:

Code:
ReiserFS: hda5: found reiserfs format "3.6" with standard journal
ReiserFS: hda5: using ordered data mode
ReiserFS: hda5: journal params: device hda5, size 8192, journal first block 18, max trans len 1024, max batch 900, max commit age 3
0, max trans age 30
ReiserFS: hda5: checking transaction log (hda5)
ReiserFS: hda5: journal-1153: found in header: first_unflushed_offset 5656, last_flushed_trans_id 59966
ReiserFS: hda5: journal-1206: Starting replay from offset 257556303844888, trans_id 0
ReiserFS: hda5: journal-1299: Setting newest_mount_id to 109
ReiserFS: hda5: Using r5 hash to sort names
VFS: Mounted root (reiserfs filesystem) readonly.
Mounted devfs on /dev
Freeing unused kernel memory: 180k freed
Adding 1004052k swap on /dev/hda3.  Priority:-1 extents:1
nvidia: module license 'NVIDIA' taints kernel.
ACPI: PCI Interrupt Link [LNKA] enabled at IRQ 11
PCI: setting IRQ 11 as level-triggered
ACPI: PCI interrupt 0000:01:00.0[A] -> GSI 11 (level, low) -> IRQ 11
NVRM: loading NVIDIA Linux x86 NVIDIA Kernel Module  1.0-6629  Wed Nov  3 13:12:51 PST 2004
NTFS volume version 3.1.
ReiserFS: hda6: found reiserfs format "3.6" with standard journal
ReiserFS: hda6: warning: CONFIG_REISERFS_CHECK is set ON
ReiserFS: hda6: warning: - it is slow mode for debugging.
ReiserFS: hda6: using ordered data mode
ReiserFS: hda6: journal params: device hda6, size 8192, journal first block 18, max trans len 1024, max batch 900, max commit age 3
0, max trans age 30
ReiserFS: hda6: checking transaction log (hda6)
ReiserFS: hda6: journal-1153: found in header: first_unflushed_offset 3437, last_flushed_trans_id 43392
ReiserFS: hda6: journal-1206: Starting replay from offset 186371515878765, trans_id 0
ReiserFS: hda6: journal-1299: Setting newest_mount_id to 107
ReiserFS: hda6: Using r5 hash to sort names
NTFS volume version 3.1.
ReiserFS: hdb1: found reiserfs format "3.6" with standard journal
ReiserFS: hdb1: warning: CONFIG_REISERFS_CHECK is set ON
ReiserFS: hdb1: warning: - it is slow mode for debugging.
ReiserFS: hdb1: using ordered data mode
ReiserFS: hdb1: journal params: device hdb1, size 8192, journal first block 18, max trans len 1024, max batch 900, max commit age 3
0, max trans age 30
ReiserFS: hdb1: checking transaction log (hdb1)
ReiserFS: hdb1: journal-1153: found in header: first_unflushed_offset 3636, last_flushed_trans_id 499
ReiserFS: hdb1: journal-1206: Starting replay from offset 2147483651636, trans_id 0
ReiserFS: hdb1: journal-1299: Setting newest_mount_id to 34
ReiserFS: hdb1: Using r5 hash to sort names
NTFS volume version 3.1.
 
Old 03-17-2005, 11:35 AM   #12
Godsmacker777
Member
 
Registered: Oct 2004
Posts: 52

Original Poster
Rep: Reputation: 15
I am not doing my coding work on a "data" partition mounted exec. I guess this has become a mounting problem. If people would like I can post this issue in the relevent forum and spare getting off topic here. Though it doesn't look like it is a big problem, just a small detail I am overlooking somewhere.

I thank all of you who helped.
 
  


Reply



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
basic java programming question nkoplm Programming 3 09-22-2005 01:37 AM
I want some guide to know the basic about device drivers programming in linux. kadhiravan.r Linux - Software 2 07-18-2005 07:07 AM
Basic Linux Question. rvijay Linux - Distributions 5 03-06-2005 12:16 PM
Basic Linux Programming Question (QT terminal control) Boffy Programming 5 09-09-2004 12:44 PM
I'm a BASIC chap, looking for some info on BASIC programming CragStar Programming 2 01-21-2001 09:19 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:31 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration