Skip to content

Commit 055ce58

Browse files
acmelgregkh
authored andcommitted
perf tools: Use readdir() instead of deprecated readdir_r()
commit 7093b4c963cc4e344e490c774924a180602a7092 upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 144eb3e commit 055ce58

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

tools/perf/util/event.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ static int __event__synthesize_thread(union perf_event *comm_event,
416416
{
417417
char filename[PATH_MAX];
418418
DIR *tasks;
419-
struct dirent dirent, *next;
419+
struct dirent *dirent;
420420
pid_t tgid, ppid;
421421
int rc = 0;
422422

@@ -445,11 +445,11 @@ static int __event__synthesize_thread(union perf_event *comm_event,
445445
return 0;
446446
}
447447

448-
while (!readdir_r(tasks, &dirent, &next) && next) {
448+
while ((dirent = readdir(tasks)) != NULL) {
449449
char *end;
450450
pid_t _pid;
451451

452-
_pid = strtol(dirent.d_name, &end, 10);
452+
_pid = strtol(dirent->d_name, &end, 10);
453453
if (*end)
454454
continue;
455455

@@ -558,7 +558,7 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
558558
{
559559
DIR *proc;
560560
char proc_path[PATH_MAX];
561-
struct dirent dirent, *next;
561+
struct dirent *dirent;
562562
union perf_event *comm_event, *mmap_event, *fork_event;
563563
int err = -1;
564564

@@ -583,9 +583,9 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
583583
if (proc == NULL)
584584
goto out_free_fork;
585585

586-
while (!readdir_r(proc, &dirent, &next) && next) {
586+
while ((dirent = readdir(proc)) != NULL) {
587587
char *end;
588-
pid_t pid = strtol(dirent.d_name, &end, 10);
588+
pid_t pid = strtol(dirent->d_name, &end, 10);
589589

590590
if (*end) /* only interested in proper numerical dirents */
591591
continue;

0 commit comments

Comments
 (0)