Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1686717

[PATCH 4.4 41/57] perf thread_map: Use readdir() instead of deprecated readdir_r()

From Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Newsgroups linux.kernel
Subject [PATCH 4.4 41/57] perf thread_map: Use readdir() instead of deprecated readdir_r()
Date 2017-07-13 18:00 +0200
Message-ID <u2OH2-7vy-47@gated-at.bofh.it> (permalink)
References <u2Oxj-7s0-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


4.4-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Arnaldo Carvalho de Melo <acme@redhat.com>

commit 3354cf71104de49326d19d2f9bdb1f66eea52ef4 upstream.

The readdir() function is thread safe as long as just one thread uses a
DIR, which is the case in thread_map, so, to avoid breaking the build
with glibc-2.23.90 (upcoming 2.24), use it instead of readdir_r().

See: http://man7.org/linux/man-pages/man3/readdir.3.html

"However, in modern implementations (including the glibc implementation),
concurrent calls to readdir() that specify different directory streams
are thread-safe.  In cases where multiple threads must read from the
same directory stream, using readdir() with external synchronization is
still preferable to the use of the deprecated readdir_r(3) function."

Noticed while building on a Fedora Rawhide docker container.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-del8h2a0f40z75j4r42l96l0@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 tools/perf/util/thread_map.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

--- a/tools/perf/util/thread_map.c
+++ b/tools/perf/util/thread_map.c
@@ -93,7 +93,7 @@ struct thread_map *thread_map__new_by_ui
 	DIR *proc;
 	int max_threads = 32, items, i;
 	char path[NAME_MAX + 1 + 6];
-	struct dirent dirent, *next, **namelist = NULL;
+	struct dirent *dirent, **namelist = NULL;
 	struct thread_map *threads = thread_map__alloc(max_threads);
 
 	if (threads == NULL)
@@ -106,16 +106,16 @@ struct thread_map *thread_map__new_by_ui
 	threads->nr = 0;
 	atomic_set(&threads->refcnt, 1);
 
-	while (!readdir_r(proc, &dirent, &next) && next) {
+	while ((dirent = readdir(proc)) != NULL) {
 		char *end;
 		bool grow = false;
 		struct stat st;
-		pid_t pid = strtol(dirent.d_name, &end, 10);
+		pid_t pid = strtol(dirent->d_name, &end, 10);
 
 		if (*end) /* only interested in proper numerical dirents */
 			continue;
 
-		snprintf(path, sizeof(path), "/proc/%s", dirent.d_name);
+		snprintf(path, sizeof(path), "/proc/%s", dirent->d_name);
 
 		if (stat(path, &st) != 0)
 			continue;

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 4.4 00/57] 4.4.77-stable review Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-13 17:50 +0200
  [PATCH 4.4 27/57] ath10k: override CE5 config for QCA9377 Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-13 17:50 +0200
  [PATCH 4.4 12/57] usb: Fix typo in the definition of Endpoint[out]Request Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-13 17:50 +0200
  [PATCH 4.4 50/57] md: fix incorrect use of lexx_to_cpu in does_sb_need_changing Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-13 17:50 +0200
  [PATCH 4.4 54/57] staging: comedi: fix clean-up of comedi_class in comedi_init() Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-13 17:50 +0200
  [PATCH 4.4 11/57] usb: usbip: set buffer pointers to NULL after free Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-13 17:50 +0200
  [PATCH 4.4 45/57] perf pmu: Fix misleadingly indented assignment (whitespace) Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-13 17:50 +0200
  [PATCH 4.4 13/57] mac80211_hwsim: Replace bogus hrtimer clockid Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-13 18:00 +0200
  [PATCH 4.4 39/57] perf bench numa: Avoid possible truncation when using snprintf() Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-13 18:00 +0200
  [PATCH 4.4 10/57] Add USB quirk for HVR-950q to avoid intermittent device resets Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-13 18:00 +0200
  [PATCH 4.4 06/57] tracing/kprobes: Allow to create probe with a module name starting with a digit Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-13 18:00 +0200
  [PATCH 4.4 02/57] fs: completely ignore unknown open flags Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-13 18:00 +0200
  [PATCH 4.4 09/57] USB: serial: cp210x: add ID for CEL EM3588 USB ZigBee stick Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-13 18:00 +0200
  [PATCH 4.4 43/57] perf tools: Remove duplicate const qualifier Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-13 18:00 +0200
  [PATCH 4.4 31/57] tools include: Add a __fallthrough statement Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-13 18:00 +0200
  [PATCH 4.4 16/57] pinctrl: sh-pfc: r8a7791: Fix SCIF2 pinmux data Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-13 18:00 +0200
  [PATCH 4.4 15/57] sysctl: report EINVAL if value is larger than UINT_MAX for proc_douintvec Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-13 18:00 +0200
  [PATCH 4.4 37/57] perf scripting perl: Fix compile error with some perl5 versions Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-13 18:00 +0200
  [PATCH 4.4 41/57] perf thread_map: Use readdir() instead of deprecated readdir_r() Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-13 18:00 +0200
  [PATCH 4.4 01/57] fs: add a VALID_OPEN_FLAGS Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-13 18:00 +0200
  [PATCH 4.4 40/57] perf tools: Use readdir() instead of deprecated readdir_r() Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-13 18:00 +0200
  [PATCH 4.4 34/57] perf top: Use __fallthrough Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-13 18:00 +0200
  [PATCH 4.4 33/57] tools strfilter: Use __fallthrough Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-13 18:00 +0200
  [PATCH 4.4 32/57] tools string: Use __fallthrough in perf_atoll() Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-13 18:00 +0200
  [PATCH 4.4 19/57] pinctrl: sunxi: Fix SPDIF function name for A83T Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-13 18:00 +0200
  [PATCH 4.4 35/57] perf intel-pt: Use __fallthrough Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-13 18:00 +0200
  [PATCH 4.4 17/57] pinctrl: sh-pfc: r8a7791: Add missing DVC_MUTE signal Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-13 18:00 +0200
  Re: [PATCH 4.4 00/57] 4.4.77-stable review Guenter Roeck <linux@roeck-us.net> - 2017-07-14 03:40 +0200
    Re: [PATCH 4.4 00/57] 4.4.77-stable review Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-14 12:00 +0200
      Re: [PATCH 4.4 00/57] 4.4.77-stable review Guenter Roeck <linux@roeck-us.net> - 2017-07-14 21:30 +0200
        Re: [PATCH 4.4 00/57] 4.4.77-stable review Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-15 10:20 +0200
  Re: [PATCH 4.4 00/57] 4.4.77-stable review Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-14 12:00 +0200
    Re: [PATCH 4.4 00/57] 4.4.77-stable review Arnd Bergmann <arnd@arndb.de> - 2017-07-14 14:30 +0200
      Re: [PATCH 4.4 00/57] 4.4.77-stable review Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-14 15:30 +0200
        Re: [PATCH 4.4 00/57] 4.4.77-stable review Arnd Bergmann <arnd@arndb.de> - 2017-07-14 22:00 +0200
        Re: [PATCH 4.4 00/57] 4.4.77-stable review Geert Uytterhoeven <geert@linux-m68k.org> - 2017-07-15 13:20 +0200
          Re: [PATCH 4.4 00/57] 4.4.77-stable review Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-15 13:30 +0200
    Re: [PATCH 4.4 00/57] 4.4.77-stable review Mark Brown <broonie@kernel.org> - 2017-07-14 14:40 +0200
      Re: [PATCH 4.4 00/57] 4.4.77-stable review Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-07-14 15:30 +0200

csiph-web