bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dup2/fcntl(F_DUPFD) on haiku


From: Eric Blake
Subject: Re: dup2/fcntl(F_DUPFD) on haiku
Date: Tue, 25 Jan 2011 22:38:13 -0700
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.7

On 01/25/2011 10:02 PM, Eric Blake wrote:
> test-dup2 and test-fcntl are failing on Haiku when using both the dup2
> and cloexec modules in tandem.  I tested on Haiku alpha 2 (the latest
> formal release per haiku-os.org) rather than a nightly build, so this
> may have already been fixed by upstream development.  But it seems like
> I should be able to come up with workarounds.

Also:

$ cat foo.c
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
int main() {
  int fd1;
  int fd2;
  int i;

  fd1 = fcntl(0, F_DUPFD);
  fcntl(fd1, F_SETFD, FD_CLOEXEC);
  i = fcntl(fd1, F_GETFD);
  printf("before %d\n", i);

  fd2 = fcntl(fd1, F_DUPFD, fd2);
  i = fcntl(fd1, F_GETFD);
  printf("middle %d", i);
  i = fcntl(fd2, F_GETFD);
  printf(" %d\n", i);

  fcntl(fd1, F_SETFD, FD_CLOEXEC);
  i = fcntl(fd1, F_GETFD);
  printf("after %d", i);
  i = fcntl(fd2, F_GETFD);
  printf(" %d\n", i);
  return 0;
}
$ ./foo
before 1
middle 0 0
after 1 0

Oops - the mere act of duplicating an fd loses the FD_CLOEXEC bit on the
original; but at least it can be restored right after duplication.

-- 
Eric Blake   address@hidden    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]