Replace deprecated readdir_r() with readdir()
authorMichael Jeanson <mjeanson@efficios.com>
Tue, 5 Jun 2018 16:11:20 +0000 (12:11 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 5 Jun 2018 17:10:17 +0000 (13:10 -0400)
readdir_r() has been deprecated since glibc 2.24 [1].

We used readdir_r() in load_session_from_path() to be thread-safe
since this function is part of liblttng-ust-ctl. However, according
to readdir()'s man page, it's thread-safe as long as the directory
stream it operates on is not shared across threads :

  In the current POSIX.1 specification (POSIX.1-2008), readdir(3) is
  not required to be thread-safe. However, in modern
  implementations (including the glibc implementation), concurrent
  calls to readdir(3) that specify different directory streams are
  thread-safe. Therefore, the use of readdir_r() is generally
  unnecessary in multithreaded programs. In cases where multiple
  threads must read from the same directory stream, using readdir(3)
  with external synchronization is still preferable to the use of
  readdir_r(), for the reasons given in the points above.

In our use-case where we open the directory stream in the same function,
we know it won't be shared across threads and thus it's safe to use
readdir(). Here is the relevevant bit from the POSIX.1 [2] spec :

  The returned pointer, and pointers within the structure, might be
  invalidated or the structure or the storage areas might be overwritten
  by a subsequent call to readdir() on the same directory stream. They shall
  not be affected by a call to readdir() on a different directory stream.

[1] https://sourceware.org/bugzilla/show_bug.cgi?id=19056
[2] http://pubs.opengroup.org/onlinepubs/9699919799/functions/readdir.html

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>

No differences found
This page took 0.025032 seconds and 4 git commands to generate.