Re: fork/execv - how to get errno to the parent



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



Relevant Pages

  • Re: Not entirely OT: RSHELL to Solaris
    ... > Andrew Harrison SUNUK Consultancy wrote: ... remotely execute the shell script on the Sun from ... OpenVMS form inside something like DCL. ... the OpenVMS user executing the remote command. ...
    (comp.os.vms)
  • Re: [kde-linux] Please Help!
    ... executing a shell script program? ... you could add an association to the mime type ... paste text into the konsole window and the shell script would see it on ... New GPG Key! ...
    (KDE)
  • Re: Execute all files and log outputs
    ... The log file should have the ... I think we need to exclude the shell script itself, ... otherwise it'll forever executing itself. ... # Create outputs directory if it doesn't exit ...
    (comp.unix.shell)
  • Re: weird behaviour with less
    ... shell script. ... How or why this would end up executing a .cshrc, ... so it only gets executed on login shells. ...
    (Fedora)