perf record: Fix race where process can disappear while reading its /proc/pid/tasks
authorArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 26 Oct 2009 21:23:17 +0000 (19:23 -0200)
committerIngo Molnar <mingo@elte.hu>
Tue, 27 Oct 2009 12:51:53 +0000 (13:51 +0100)
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

index ac5ddfff44561b2f3d7771b16cb9425c8d861eec..9e1638cc19c8a83ce13e6452b42e63b0ee12efa5 100644 (file)
@@ -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);