public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Mark Olesen via Libc-alpha <libc-alpha@sourceware.org>
Cc: Mark Olesen <markjolesen@gmail.com>
Subject: Re: readdir and ENOENT error or EOF?
Date: Thu, 17 Jun 2021 09:07:32 +0200	[thread overview]
Message-ID: <87h7hx6kaz.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <CAExh6bawFgk2BtuET-0gx+VmGw=BPRWWGoBp_oOEtwtDh7es5Q@mail.gmail.com> (Mark Olesen via Libc-alpha's message of "Wed, 16 Jun 2021 14:49:41 -0600")

* Mark Olesen via Libc-alpha:

> There appears to be ambiguity in user documentation for readdir when
> it returns NULL and errno is set to ENOENT.
>
> Is this an EOF condition or an actual error that should be handled?
>
> ...
> /* On some systems getdents fails with ENOENT when the
> open directory has been rmdir'd already. POSIX.1
> requires that we treat this condition like normal EOF. */
> if (bytes < 0 && errno == ENOENT)
> bytes = 0;
> ...
> https://code.woboq.org/userspace/glibc/sysdeps/posix/readdir.c.htmlin

Note that the Linux implementation is in
sysdeps/unix/sysv/linux/readdir.c, but it has this quirk as well.

I believe this has been copied over from historic times.  In general,
Linux handles this corner case differently.  However, the Linux VFS
layer will pass through ENOENT from file system implementations, so if a
file system implementation generates ENOENT in its readdir
implementation, we might still see ENOENT in userspace.  That's why it's
difficult to remove the check from glibc's readdir implementation.

Thanks,
Florian


  reply	other threads:[~2021-06-17  7:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-16 20:49 Mark Olesen
2021-06-17  7:07 ` Florian Weimer [this message]
2021-06-18 18:02   ` Mark Olesen
2021-06-22  7:53     ` Florian Weimer
2021-06-22  8:18       ` Andreas Schwab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h7hx6kaz.fsf@oldenburg.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=markjolesen@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).