On 01/25/2011 10:38 PM, Eric Blake wrote:
> 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.
> 
> 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.

Not just that, but:

$ cat foo.c
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
int main() {
  int i;
  fcntl(0, F_SETFD, FD_CLOEXEC);
  i = fcntl(0, F_GETFD);
  printf("%d\n", i);
  i = dup2(0, 0);
  printf("%d %d\n", i, errno);
  i = fcntl(0, F_GETFD);
  printf("%d\n", i);
  return 0;
}
$ ./foo
1
0 0
0

dup2(fd, fd), which is supposed to be a nop, is clearing the cloexec bit.

-- 
Eric Blake   [email protected]    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to