From: Arnaldo Carvalho de Melo Date: Mon, 26 Oct 2009 21:23:17 +0000 (-0200) Subject: perf record: Fix race where process can disappear while reading its /proc/pid/tasks X-Git-Tag: firefly_0821_release~9833^2~3628^2~288^2~47 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=7f3bedcc93f935631d2363f23de1cc80f04fdf3e;p=firefly-linux-kernel-4.4.55.git perf record: Fix race where process can disappear while reading its /proc/pid/tasks Signed-off-by: Arnaldo Carvalho de Melo Cc: Frederic Weisbecker Cc: Peter Zijlstra Cc: Paul Mackerras Cc: Mike Galbraith LKML-Reference: <1256592199-9608-1-git-send-email-acme@redhat.com> Signed-off-by: Ingo Molnar --- diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index ac5ddfff4456..9e1638cc19c8 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -206,6 +206,7 @@ static pid_t pid_synthesize_comm_event(pid_t pid, int full) fp = fopen(filename, "r"); if (fp == NULL) { +out_race: /* * We raced with a task exiting - just return: */ @@ -247,6 +248,9 @@ static pid_t pid_synthesize_comm_event(pid_t pid, int full) snprintf(filename, sizeof(filename), "/proc/%d/task", pid); tasks = opendir(filename); + if (tasks == NULL) + goto out_race; + while (!readdir_r(tasks, &dirent, &next) && next) { char *end; pid = strtol(dirent.d_name, &end, 10);