All of lore.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Arnaldo Carvalho de Melo <acme@redhat.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, paulus@samba.org, acme@redhat.com,
	hpa@zytor.com, mingo@redhat.com, efault@gmx.de,
	peterz@infradead.org, fweisbec@gmail.com, tglx@linutronix.de,
	mingo@elte.hu
Subject: [tip:perf/core] perf record: Fix race where process can disappear while reading its /proc/pid/tasks
Date: Tue, 27 Oct 2009 13:03:32 GMT	[thread overview]
Message-ID: <tip-7f3bedcc93f935631d2363f23de1cc80f04fdf3e@git.kernel.org> (raw)
In-Reply-To: <1256592199-9608-1-git-send-email-acme@redhat.com>

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);

      parent reply	other threads:[~2009-10-27 13:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-26 21:23 [PATCH 1/3] perf record: process can disappear while reading its /proc/pid/tasks Arnaldo Carvalho de Melo
2009-10-26 21:23 ` [PATCH 2/3] perf tools: Generalize event synthesizing routines Arnaldo Carvalho de Melo
2009-10-26 21:23   ` [PATCH 3/3] perf top: Support userspace symbols too Arnaldo Carvalho de Melo
2009-10-27 13:00     ` Ingo Molnar
2009-10-27 13:04     ` [tip:perf/core] " tip-bot for Arnaldo Carvalho de Melo
2009-10-27 13:03   ` [tip:perf/core] perf tools: Generalize event synthesizing routines tip-bot for Arnaldo Carvalho de Melo
2009-10-27 13:03 ` tip-bot for Arnaldo Carvalho de Melo [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-7f3bedcc93f935631d2363f23de1cc80f04fdf3e@git.kernel.org \
    --to=acme@redhat.com \
    --cc=efault@gmx.de \
    --cc=fweisbec@gmail.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=mingo@redhat.com \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.