LinuxQuestions.org
Review your favorite Linux distribution.
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 07-09-2011, 11:45 AM   #1
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
A few questions about execve()'s errors


There are some things that I don'r really get about execve()'s errors:

Quote:
Originally Posted by man 2 execve
EFAULT filename points outside your accessible address space.
What does that mean? My only guess is that it means that the "char *filename" argument points to non-allocated memory, is that right?

Quote:
Originally Posted by man 2 execve
EINVAL An ELF executable had more than one PT_INTERP segment (i.e., tried to name more than one interpreter).

ELIBBAD An ELF interpreter was not in a recognized format.
What is the ELF interpreter? I thought it was the kernel that read ELF files.

Quote:
Originally Posted by man 2 execve
EISDIR An ELF interpreter was a directory.

ENOTDIR A component of the path prefix of filename or a script or ELF interpreter is not a directory.
So it's an error if it is a directory, and it's an error if it's not a directory?!?!?!?

And finally, what error code is used if the interpreter specified in a shebang line doesn't exist or can't be executed for some reason?

Last edited by MTK358; 07-09-2011 at 11:48 AM.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 07-10-2011, 07:34 AM   #2
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
Quote:
Originally Posted by MTK358 View Post
[execve(): EFAULT] What does that mean? My only guess is that it means that the "char *filename" argument points to non-allocated memory, is that right?
Yes, exactly.

Quote:
Originally Posted by MTK358 View Post
What is the ELF interpreter? I thought it was the kernel that read ELF files.
Yes, but all (non-static) ELF binaries require some linking at run time, done by an ELF dynamic linker or loader, also called the ELF interpreter. In Linux, this is usually /lib/ld-linux.so.

The .interp section in ELF files names the (path to the) linker needed for that program. You can use objdump -d -j .interp program to dump the contents of that section for any program. (It is just a zero-terminated string.)

Quote:
Originally Posted by MTK358 View Post
[execve(): EISDIR]
This happens when the linker points to a directory. For example, if /lib/ld-linux.so was a directory and not a file.

(If you decide to test that in real life, keep alternate boot media handy, or use busybox. There are only a few commands that will keep working..)

Quote:
Originally Posted by MTK358 View Post
[execve(): ENOTDIR]
This happens when you have a path where one of the parents is a file and not a directory. For example, if /lib was a file and not a directory.

Quote:
Originally Posted by MTK358 View Post
And finally, what error code is used if the interpreter specified in a shebang line doesn't exist or can't be executed for some reason?
ENOENT for the former, EACCES for the latter.

Script files with a shebang line are handled in a manner that reminds me of symlinks: the kernel inspects the shebang line (or more of the file, if binfmt_misc kernel module is used), and continues as if the first parameter (file name) specified in the execve() call had been the named interpreter instead. In that way, the error codes make sense: ENOENT, because later on the kernel finds that the file name specified does not exist, and EACCES because it cannot be executed.
 
2 members found this post helpful.
  


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
Problem in execve function vinayl Linux - Kernel 0 01-26-2008 07:34 AM
Compiled first 2.6 kernel - Questions and errors found Elukyz Slackware 3 06-30-2007 11:55 PM
Postfix errors, questions Phaethar Linux - Software 0 12-15-2003 08:38 AM
Using execve() not working cxel91a Programming 3 09-03-2003 06:26 AM
fork() and execve() Alf829 Programming 3 08-02-2003 10:18 AM

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

All times are GMT -5. The time now is 12:34 PM.

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