views:

112

answers:

3

I am using the POSIX call nftw() for traversing a directory structure. The directory structure is flat - only 4 files and no subdirectories.

However when I call nftw() a lot of times on this flat directory then I get an error message after a while:

"too many open file handles".

It turned out that this happens when the flag FTW_CHDIR is used.

Would you agree that it is a bug in the Linux implementation of nftw() ?

UPDATE

A fix is now available in the glibc repositories.

here are some links to the source code I have used for testing:

UPDATE

  • MacOS-X is also hit by the bug
  • Solaris9, Solaris10 and AIX 5.3 do not have the bug
+8  A: 

For me it looks like there is really something wrong with the nftw implementation on linux.

I have filed a bug report, see here

UPDATE: A fix is available in the glibc repositories now.

wow, that was a quick fix - http://sourceware.org/git/?p=glibc.git;a=commit;h=247fdf2e2b798378d8aeaac1ee6f4ba0a49f31f3
mark4o
+1 for filing the bug report, and the follow-up.
Alok
+2  A: 

It has the same behaviour on Mac OS 10.6.2. So probably somehow part of the specification, though I don't see how exactly.

FX
that's interesting. Our real world code is multiplatform - including MacOS. I'm going to check tomorrow if it happens within our MacOS application too.
+3  A: 

Regarding Mac OS: bugreport submitted to Apple as radar #7640283. (No hyperlink possible, unfortunately.)

FX
Given that Apple's BSD bits are mostly identical to FreeBSD's, I wonder if it's a bug inherited from there.
ephemient