0417 snapshot: exec() fails on /proc/self/exe

Eric Blake eblake@redhat.com
Wed Apr 20 02:06:00 GMT 2011


On 04/19/2011 02:16 PM, Andy Koppe wrote:
> int main(int argc, char *argv[])
> {
>   if (argc > 1 && !fork()) {
>     execl("/proc/self/exe", argv[0], (char *)0);
>     puts(strerror(errno));
>   }
>   return 0;
> }
> 
> $ cc test.c
> 
> $ ./a bla
> Bad file descriptor
> 
> With 1.7.9, it prints nothing, which is the expected behaviour.
> Looking at POSIX, EBADF is not a valid errno for exec().

EBADF is not listed for execl(), but _is_ listed for fexecve(), and when
you consider that /proc/self is a special file system that opens file
descriptors rather than files, it makes (a bit) of sense.  At any rate,
POSIX states that other errors than those documented (such as EBADF for
execl()) may be returned if the condition for those errors matches other
use of that errno value and does not skip over any existing mandated
errors.  It also means that maybe cygwin should behave as if O_EXEC
rather than O_RDONLY were used when populating "/proc/self/exe", seeing
as how execl() on that file basically boils down to an fexecve() call.

-- 
Eric Blake   eblake@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <http://cygwin.com/pipermail/cygwin/attachments/20110420/345f9457/attachment.sig>


More information about the Cygwin mailing list