public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* 0417 snapshot: exec() fails on /proc/self/exe
@ 2011-04-19 22:38 Andy Koppe
  2011-04-20  2:06 ` Eric Blake
  2011-04-20 11:59 ` Andy Koppe
  0 siblings, 2 replies; 4+ messages in thread
From: Andy Koppe @ 2011-04-19 22:38 UTC (permalink / raw)
  To: cygwin

With the latest snapshot, exec() fails on /proc/self/exe:

$ cat test.c
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>

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

(The argument in the test is there as a way to stop it from becoming a
fork bomb.)

Andy

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: 0417 snapshot: exec() fails on /proc/self/exe
  2011-04-19 22:38 0417 snapshot: exec() fails on /proc/self/exe Andy Koppe
@ 2011-04-20  2:06 ` Eric Blake
  2011-04-20 11:59 ` Andy Koppe
  1 sibling, 0 replies; 4+ messages in thread
From: Eric Blake @ 2011-04-20  2:06 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 1177 bytes --]

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


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 620 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: 0417 snapshot: exec() fails on /proc/self/exe
  2011-04-19 22:38 0417 snapshot: exec() fails on /proc/self/exe Andy Koppe
  2011-04-20  2:06 ` Eric Blake
@ 2011-04-20 11:59 ` Andy Koppe
  2011-04-20 13:16   ` Corinna Vinschen
  1 sibling, 1 reply; 4+ messages in thread
From: Andy Koppe @ 2011-04-20 11:59 UTC (permalink / raw)
  To: cygwin

On 19 April 2011 21:16, Andy Koppe wrote:
> With the latest snapshot, exec() fails on /proc/self/exe:
>
> $ cat test.c
> #include <stdio.h>
> #include <stdlib.h>
> #include <errno.h>
> #include <unistd.h>
> #include <string.h>
>
> 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().

No need for that test case actually. Symbolic links within /proc just
seem to be broken:

$ ls -l /proc/self/exe
ls: cannot read symbolic link /proc/self/exe: Invalid argument
lrwxrwxrwx 1 Andy None 0 Apr 20 06:15 /proc/self/exe

$ ls -l /proc/3372
ls: cannot read symbolic link /proc/3372/cwd: Invalid argument
ls: cannot read symbolic link /proc/3372/exe: Invalid argument
ls: cannot read symbolic link /proc/3372/root: Invalid argument
total 0
-r--r--r-- 1 Andy None 0 Apr 20 06:14 cmdline
-r--r--r-- 1 Andy None 0 Apr 20 06:14 ctty
lrwxrwxrwx 1 Andy None 0 Apr 20 06:14 cwd
lrwxrwxrwx 1 Andy None 0 Apr 20 06:14 exe
-r--r--r-- 1 Andy None 0 Apr 20 06:14 exename
...

Andy

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: 0417 snapshot: exec() fails on /proc/self/exe
  2011-04-20 11:59 ` Andy Koppe
@ 2011-04-20 13:16   ` Corinna Vinschen
  0 siblings, 0 replies; 4+ messages in thread
From: Corinna Vinschen @ 2011-04-20 13:16 UTC (permalink / raw)
  To: cygwin

On Apr 20 06:15, Andy Koppe wrote:
> No need for that test case actually. Symbolic links within /proc just
> seem to be broken:

Fixed in CVS.  Just an oversight when the /proc virtual devices
have been renumbered a couple of days ago.


Thanks for the report,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-04-20  7:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-19 22:38 0417 snapshot: exec() fails on /proc/self/exe Andy Koppe
2011-04-20  2:06 ` Eric Blake
2011-04-20 11:59 ` Andy Koppe
2011-04-20 13:16   ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).