LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   basic linux programming/compiling question (permissions error) (https://www.linuxquestions.org/questions/programming-9/basic-linux-programming-compiling-question-permissions-error-302424/)

Godsmacker777 03-16-2005 03:13 PM

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

Mara 03-16-2005 03:16 PM

Interesting. Please show us how the permissions and ownership looks after you compile. Run:
ls -l a.out
and post the result.

wapcaplet 03-16-2005 03:20 PM

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!

Godsmacker777 03-16-2005 04:28 PM

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.

Dark_Helmet 03-16-2005 04:56 PM

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.

Godsmacker777 03-16-2005 05:47 PM

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.

gbonvehi 03-16-2005 07:31 PM

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)

Godsmacker777 03-16-2005 11:16 PM

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?

Dark_Helmet 03-17-2005 12:16 AM

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.

gbonvehi 03-17-2005 04:27 AM

[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.

Godsmacker777 03-17-2005 11:32 AM

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.


Godsmacker777 03-17-2005 11:35 AM

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. :D


All times are GMT -5. The time now is 09:55 PM.