Re: readdir() loses entries on ramfs and tmpfs

Edgar Toernig (froese@gmx.de)
Thu, 27 Dec 2001 02:52:42 +0100


Pavel Roskin wrote:
>
> while ((d = readdir(dir)) != NULL) {
> printf("%s\n", d->d_name);
> rmdir(d->d_name);
> }
>[...]
> Basically, removing a subdirectory in a directory open with opendir()
> causes an entry (file or directory) 168 entries later to be skipped by
> readdir().
>
> I'm sorry, I cannot elaborate more, but the issue seems to be very
> serious.

Not nice but not serious. Modifying the directory you scan is
never save and programs relying on this are broken. You can
build a list of items to work on but even then another process
may add new entries or remove some and you have to handle that.
One could "fix" your "bug" but the program will still be broken.

Ciao, ET.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/