linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Michael Kerrisk (man-pages)" <mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Florian Weimer <fweimer-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
	Siddhesh Poyarekar
	<siddhesh-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Cc: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
	Rich Felker <dalias-/miJ2pyFWUyWIDz0JBNUog@public.gmane.org>,
	Carlos O'Donell <carlos-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
	KOSAKI Motohiro
	<kosaki.motohiro-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	libc-alpha <libc-alpha-9JcytcrH/bA+uJoB2kUjGw@public.gmane.org>,
	Roland McGrath <roland-/Z5OmTQCD9xF6kxbq+BtvQ@public.gmane.org>,
	linux-man <linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: [PATCH] Fix readdir_r with long file names
Date: Tue, 1 Mar 2016 21:14:42 +0100	[thread overview]
Message-ID: <56D5F832.3070209@gmail.com> (raw)
In-Reply-To: <56D5CA79.9030204-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>

Hi Florian,

On 03/01/2016 05:59 PM, Florian Weimer wrote:
> On 03/01/2016 09:07 AM, Michael Kerrisk (man-pages) wrote:
> 
>> I see that glibc 2.23 deprecates readdir_r(), which prompted me to catch
>> up on this thread. I'd like to see the points you make documented in the
>> readdir_r(3) man page also. Would you be willing to allow that text to
>> be reused / reworked for the page, under that page's existing "verbatim"
>> license (https://www.kernel.org/doc/man-pages/licenses.html#verbatim)?
> 
> Hi Michael,
> 
> thanks for keeping an eye on deprecations.  The deprecation happened for
> glibc 2.24 (unrelased).

Ah yes, I was getting ahead of myself. Fixed that in the page text below.

> I'm happy to report that I may grant your request.

Thanks!

>> The text I'd propose to add to the man page would be (new material
>> starting at ===>):
> 
> It may make sense to move this documentation to a separate manual page,
> specific to readdir_r.  This will keep the readdir documentation nice
> and crisp.  Most programmers will never have to consult all these details.

Yes, seems reasonable. Done.

> You should remove the example using pathconf because it is not correct.

Done.

>  The kernel does not return valid values for _PC_NAME_MAX and some file
> systems (such as CIFS, and CD-ROMs with Joliet extensions once a kernel
> bug is fixed).  The CIFS limit is somewhere around 765, and not 255 as
> reported by the kernel.  If I recall correctly, Windows SMB servers can
> actually exceed the 255 byte limit.  The reason is that Windows NTFS has
> a limit based on 16-bit UCS-2 characters, and after UTF-8 conversion,
> the maximum length is more than 255 bytes.

What happens with readdir() when it gets a filename that is larger 
than 255 characters?
> 
>> ===>   However, the above approach has problems, and it is recommended
>>        that  applications  use readdir() instead of readdir_r().  Fur‐
>>        thermore, since version  2.23,  glibc  deprecates  readdir_r().

s/23/24/

>>        The reasons are as follows:
>>
>>        *  On  systems where NAME_MAX is undefined, calling readdir_r()
>>           may be unsafe because the interface does not allow the call‐
>>           er to specify the length of the buffer used for the returned
>>           directory entry.
>>
>>        *  On some systems, readdir_r() can't  read  directory  entries
>>           with very long names.  When the glibc implementation encoun‐
>>           ters such a name, readdir_r() fails with the error ENAMETOO‐
>>           LONG after the final directory entry has been read.  On some
>>           other systems, readdir_r() may return a success status,  but
>>           the  returned d_name field may not be null terminated or may
>>           be truncated.
>>
>>        *  In the current POSIX.1 specification  (POSIX.1-2008),  read‐
>>           dir_r() is not required to be thread-safe.  However, in mod‐
>>           ern implementations (including  the  glibc  implementation),
>>           concurrent  calls  to  readdir_r()  that  specify  different
>>           directory streams are thread-safe.  Therefore,  the  use  of
> 
> These two references to readdir_r should be to readdir instead.

Fixed.

> 
> I believe there was a historic implementation which implemented
> fdopendir (fd) as (DIR *) fd, and used a global static buffer for
> readdir.  This is about the only way readdir can be non-thread-safe.
> 
>>           readdir_r()  is  generally unnecessary in multithreaded pro‐
>>           grams.  In cases where multiple threads must read  from  the
>>           same  directory  stream,  using readdir() with external syn‐
>>           chronization is still preferable to the use of  readdir_r(),
>>           for the reasons given in the points above.
>>
>>        *  It  is  expected  that a future version of POSIX.1 will make
>>           readdir_r() obsolete, and require that readdir() be  thread-
>>           safe  when  concurrently  employed  on  different  directory
>>           streams.

Thanks for all of the feedback Florian! The current versions of the
readdir(3) and readdir_r(3) have been pushed to the repo.

Cheers,

Michael


-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2016-03-01 20:14 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <51B0B39F.4060202@redhat.com>
     [not found] ` <51B0BD36.3030202@redhat.com>
     [not found]   ` <CAHGf_=r9Rz63pho+84ORk0a_oDyJSj-MCnZ56uPrT3L6sVEfeQ@mail.gmail.com>
     [not found]     ` <20130607013024.GO29800@brightrain.aerifal.cx>
     [not found]       ` <51B19203.3070307@redhat.com>
     [not found]         ` <20130607144143.GQ29800@brightrain.aerifal.cx>
     [not found]           ` <51B57E35.4080403@redhat.com>
     [not found]             ` <51B65EA7.2020402@redhat.com>
     [not found]               ` <20130611011324.GT29800@brightrain.aerifal.cx>
     [not found]                 ` <51B8702D.2060505@redhat.com>
     [not found]                   ` <20130813040038.GE21795@spoyarek.pnq.redhat.com>
     [not found]                     ` <520C88A6.9070501@redhat.com>
     [not found]                       ` <520C88A6.9070501-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-03-01  8:07                         ` [PATCH] Fix readdir_r with long file names Michael Kerrisk (man-pages)
2016-03-01 16:59                           ` Florian Weimer
     [not found]                             ` <56D5CA79.9030204-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-03-01 20:14                               ` Michael Kerrisk (man-pages) [this message]
     [not found]                                 ` <56D5F832.3070209-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-03-01 20:27                                   ` Florian Weimer
     [not found]                                     ` <56D5FB3D.5000306-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-03-01 21:01                                       ` Michael Kerrisk (man-pages)
     [not found]                                         ` <56D60335.7010906-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-03-01 22:21                                           ` Florian Weimer
     [not found]                                             ` <56D615D7.5020304-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-03-01 22:27                                               ` Rich Felker
2016-03-02  8:17                                               ` Michael Kerrisk (man-pages)
2016-03-01 21:20                                     ` Paul Eggert
     [not found]                                       ` <56D607BB.6080701-764C0pRuGfqVc3sceRu5cw@public.gmane.org>
2016-03-01 22:16                                         ` Florian Weimer
2016-03-01 22:41                                           ` Paul Eggert
     [not found]                                             ` <56D61A86.3050108-764C0pRuGfqVc3sceRu5cw@public.gmane.org>
2016-03-01 23:07                                               ` Florian Weimer
     [not found]                                                 ` <56D620AA.40108-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-03-01 23:25                                                   ` Paul Eggert
     [not found]                                                     ` <56D624FE.1090702-764C0pRuGfqVc3sceRu5cw@public.gmane.org>
2016-03-01 23:44                                                       ` Florian Weimer
     [not found]                                                         ` <56D6294A.5040703-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-03-02 10:39                                                           ` Michael Kerrisk (man-pages)
     [not found]                                                             ` <56D6C2CA.2020609-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-03-08 17:20                                                               ` Michael Kerrisk (man-pages)
2016-03-10 11:22                                                             ` Florian Weimer
     [not found]                                                               ` <56E158F4.6040506-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-03-10 17:06                                                                 ` Michael Kerrisk (man-pages)
2016-03-02 17:44                                                         ` Paul Eggert
     [not found]                                                           ` <56D72683.6010302-764C0pRuGfqVc3sceRu5cw@public.gmane.org>
2016-03-03 22:39                                                             ` Joseph Myers
2016-03-08 12:20                                                             ` Florian Weimer

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=56D5F832.3070209@gmail.com \
    --to=mtk.manpages-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=carlos-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=dalias-/miJ2pyFWUyWIDz0JBNUog@public.gmane.org \
    --cc=fweimer-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=kosaki.motohiro-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=libc-alpha-9JcytcrH/bA+uJoB2kUjGw@public.gmane.org \
    --cc=linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=roland-/Z5OmTQCD9xF6kxbq+BtvQ@public.gmane.org \
    --cc=siddhesh-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    /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 NNTP newsgroup(s).