lkml.org 
[lkml]   [2001]   [Dec]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: readdir() loses entries on ramfs and tmpfs
    On Wed, Dec 26, 2001 at 07:50:11PM -0500, Pavel Roskin wrote:
    > I got a report that GNU Midnight Commander fails to erase some directories
    > on tmpfs from the first attempt. However, it succeeds the next time.
    [...]
    > while ((d = readdir(dir)) != NULL) {
    > printf("%s\n", d->d_name);
    > rmdir(d->d_name);
    > }
    [...]
    > I'm sorry, I cannot elaborate more, but the issue seems to be very
    > serious.

    If Midnight Commander does similar to the above it's pretty silly...

    In Perl I normally do something like this in a loop (with a max-loops
    limiter):

    opendir
    @dirs = readdir(FOO);
    closedir
    last unless @dirs;
    &remove_the_dirs(@dirs);

    Clearly that's slack since you could have a million files in a
    directory, but you see the point. readdir(2) and getdents(2)
    are inherently racy. If your code does not assume such and take
    appropriate action, it's broken.

    Jeff


    -
    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/

    \
     
     \ /
      Last update: 2005-03-22 13:14    [W:4.530 / U:0.012 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site