basic linux programming/compiling question (permissions error)
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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!
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.
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.
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)
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?
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.