lkml.org 
[lkml]   [2009]   [Oct]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[tip:perf/core] perf record: Fix race where process can disappear while reading its /proc/pid/tasks
Commit-ID:  7f3bedcc93f935631d2363f23de1cc80f04fdf3e
Gitweb: http://git.kernel.org/tip/7f3bedcc93f935631d2363f23de1cc80f04fdf3e
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
AuthorDate: Mon, 26 Oct 2009 19:23:17 -0200
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Tue, 27 Oct 2009 13:51:53 +0100

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>
---
tools/perf/builtin-record.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index ac5ddff..9e1638c 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);

\
 
 \ /
  Last update: 2009-10-27 14:07    [W:1.207 / U:0.464 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site