bug-gnulib
[Top][All Lists]
Advanced

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

Re: fdopendir incompatibility with POSIX, with proposed patch


From: Eric Blake
Subject: Re: fdopendir incompatibility with POSIX, with proposed patch
Date: Mon, 13 Sep 2010 08:37:43 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20100827 Red Hat/3.1.3-1.el6 Mnenhy/0.8.3 Thunderbird/3.1.3

On 09/12/2010 04:18 PM, Paul Eggert wrote:
While coding up recent changes to GNU tar, I discovered a
POSIX-emulation problem in gnulib's implementation of fdopendir.
I had written code like this:


        DIR *dp = fdopendir (fd);
        int fd1 = openat (fd, "subdir", O_RDONLY);

This works with POSIX fdopendir,

Technically, our previous implementation _is_ POSIX-compliant - POSIX does not require that dirfd(fdopendir(fd))==fd. But I can see how it is confusing, and how wrapping DIR around the desired fd makes coding much easier.

How about the following patch to help ameliorate this problem?  It
would have fixed the bug for GNU tar, anyway.  (I have reworked GNU
tar to use a different approach, so this patch is not needed for GNU
tar, but still it should help avoid future gotchas like this.)  This
patch won't work in general (multithreaded apps, signal handers) but
it should work for single-threaded apps whose signal handers don't open
or close files.

Looks good to me!

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



reply via email to

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