aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-record.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2009-10-26 17:23:17 -0400
committerIngo Molnar <mingo@elte.hu>2009-10-27 08:51:53 -0400
commit7f3bedcc93f935631d2363f23de1cc80f04fdf3e (patch)
tree3fb5bc27a52e6d41395c7361c46f91d4d909a6c8 /tools/perf/builtin-record.c
parentfcd14b3203b538dca04a2b065c774c0b57863eec (diff)
perf record: Fix race where process can disappear while reading its /proc/pid/tasks
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Mike Galbraith <efault@gmx.de> LKML-Reference: <1256592199-9608-1-git-send-email-acme@redhat.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/builtin-record.c')
-rw-r--r--tools/perf/builtin-record.c4
1 files changed, 4 insertions, 0 deletions
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)
206 206
207 fp = fopen(filename, "r"); 207 fp = fopen(filename, "r");
208 if (fp == NULL) { 208 if (fp == NULL) {
209out_race:
209 /* 210 /*
210 * We raced with a task exiting - just return: 211 * We raced with a task exiting - just return:
211 */ 212 */
@@ -247,6 +248,9 @@ static pid_t pid_synthesize_comm_event(pid_t pid, int full)
247 snprintf(filename, sizeof(filename), "/proc/%d/task", pid); 248 snprintf(filename, sizeof(filename), "/proc/%d/task", pid);
248 249
249 tasks = opendir(filename); 250 tasks = opendir(filename);
251 if (tasks == NULL)
252 goto out_race;
253
250 while (!readdir_r(tasks, &dirent, &next) && next) { 254 while (!readdir_r(tasks, &dirent, &next) && next) {
251 char *end; 255 char *end;
252 pid = strtol(dirent.d_name, &end, 10); 256 pid = strtol(dirent.d_name, &end, 10);