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: v2.6.33-rc1~399^2~165^2~47 X-Git-Url: https://openfabrics.org/gitweb/?a=commitdiff_plain;h=7f3bedcc93f935631d2363f23de1cc80f04fdf3e;p=~shefty%2Frdma-dev.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 ac5ddfff445..9e1638cc19c 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);