diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-04-08 10:32:15 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-04-08 10:32:15 -0400 |
commit | 7093b4c963cc4e344e490c774924a180602a7092 (patch) | |
tree | 0faaca53625cce476490d0896db97ac1ba01118d /tools/perf | |
parent | 3354cf71104de49326d19d2f9bdb1f66eea52ef4 (diff) |
perf tools: Use readdir() instead of deprecated readdir_r()
The readdir() function is thread safe as long as just one thread uses a
DIR, which is the case when synthesizing events for pre-existing threads
by traversing /proc, 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 /tmp/build/perf/util/event.o
util/event.c: In function '__event__synthesize_thread':
util/event.c:466:2: error: 'readdir_r' is deprecated [-Werror=deprecated-declarations]
while (!readdir_r(tasks, &dirent, &next) && next) {
^~~~~
In file included from /usr/include/features.h:368:0,
from /usr/include/stdint.h:25,
from /usr/lib/gcc/x86_64-redhat-linux/6.0.0/include/stdint.h:9,
from /git/linux/tools/include/linux/types.h:6,
from util/event.c:1:
/usr/include/dirent.h:189:12: note: declared here
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-i1vj7nyjp2p750rirxgrfd3c@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/util/event.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index b68959037688..f6fcc6832949 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c | |||
@@ -434,7 +434,7 @@ static int __event__synthesize_thread(union perf_event *comm_event, | |||
434 | { | 434 | { |
435 | char filename[PATH_MAX]; | 435 | char filename[PATH_MAX]; |
436 | DIR *tasks; | 436 | DIR *tasks; |
437 | struct dirent dirent, *next; | 437 | struct dirent *dirent; |
438 | pid_t tgid, ppid; | 438 | pid_t tgid, ppid; |
439 | int rc = 0; | 439 | int rc = 0; |
440 | 440 | ||
@@ -463,11 +463,11 @@ static int __event__synthesize_thread(union perf_event *comm_event, | |||
463 | return 0; | 463 | return 0; |
464 | } | 464 | } |
465 | 465 | ||
466 | while (!readdir_r(tasks, &dirent, &next) && next) { | 466 | while ((dirent = readdir(tasks)) != NULL) { |
467 | char *end; | 467 | char *end; |
468 | pid_t _pid; | 468 | pid_t _pid; |
469 | 469 | ||
470 | _pid = strtol(dirent.d_name, &end, 10); | 470 | _pid = strtol(dirent->d_name, &end, 10); |
471 | if (*end) | 471 | if (*end) |
472 | continue; | 472 | continue; |
473 | 473 | ||
@@ -576,7 +576,7 @@ int perf_event__synthesize_threads(struct perf_tool *tool, | |||
576 | { | 576 | { |
577 | DIR *proc; | 577 | DIR *proc; |
578 | char proc_path[PATH_MAX]; | 578 | char proc_path[PATH_MAX]; |
579 | struct dirent dirent, *next; | 579 | struct dirent *dirent; |
580 | union perf_event *comm_event, *mmap_event, *fork_event; | 580 | union perf_event *comm_event, *mmap_event, *fork_event; |
581 | int err = -1; | 581 | int err = -1; |
582 | 582 | ||
@@ -601,9 +601,9 @@ int perf_event__synthesize_threads(struct perf_tool *tool, | |||
601 | if (proc == NULL) | 601 | if (proc == NULL) |
602 | goto out_free_fork; | 602 | goto out_free_fork; |
603 | 603 | ||
604 | while (!readdir_r(proc, &dirent, &next) && next) { | 604 | while ((dirent = readdir(proc)) != NULL) { |
605 | char *end; | 605 | char *end; |
606 | pid_t pid = strtol(dirent.d_name, &end, 10); | 606 | pid_t pid = strtol(dirent->d_name, &end, 10); |
607 | 607 | ||
608 | if (*end) /* only interested in proper numerical dirents */ | 608 | if (*end) /* only interested in proper numerical dirents */ |
609 | continue; | 609 | continue; |