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 [email protected] +1-801-349-2682 Libvirt virtualization library http://libvirt.org
