Re: fork/execv - how to get errno to the parent
- From: Jordan Abel <random832@xxxxxxxxx>
- Date: 24 Feb 2006 16:41:30 GMT
On 2006-02-24, Kasper Dupont <15596462440848483280@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Jordan Abel wrote:
On 2005-09-22, Kasper Dupont <kasperd@xxxxxxxxxxx> wrote:
What you must be aware of is that some of the exec functions
may actually call /bin/sh
System does this. none of the exec functions do.
What distribution are you using? I have been able to reproduce
this on Fedora Core, Source Mage, and FreeBSD. This is the
source code I used:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main()
{
char *c="foobar";
execlp(c,c,NULL);
perror(c);
return EXIT_FAILURE;
}
foobar looks like this:
echo "Hello World"
This file is not an executable file. It is a shell script. #!/bin/sh is
missing. (these facts are both important for reasons that i explain
below)
And here is the result from stracing the program:
You have mistaken an entirely different issue for what you claimed.
It is not using an exec function that searches the path that causes
/bin/sh to be executed - it is executing a shell script that doesn't
begin with a #! line.
No. the search is done in the library.
The execlp and execvp library functions are required to search the PATH.
And that is done within the library, not with a call to /bin/sh. If the
resulting execve _fails_ with the errno ENOEXEC (meaning the file was
present and executable but not in a proper executable format), it will
then try again to call /bin/sh to interpret the given file as a shell
script.
.
- References:
- Re: fork/execv - how to get errno to the parent
- From: Jordan Abel
- Re: fork/execv - how to get errno to the parent
- Prev by Date: Re: prevent multiple start of app
- Next by Date: Re: fork/execv - how to get errno to the parent
- Previous by thread: Re: fork/execv - how to get errno to the parent
- Next by thread: Re: fork/execv - how to get errno to the parent
- Index(es):
Relevant Pages
|