mirror of
https://github.com/adulau/aha.git
synced 2024-12-28 11:46:19 +00:00
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>
This commit is contained in:
parent
fcd14b3203
commit
7f3bedcc93
1 changed files with 4 additions and 0 deletions
|
@ -206,6 +206,7 @@ static pid_t pid_synthesize_comm_event(pid_t pid, int full)
|
||||||
|
|
||||||
fp = fopen(filename, "r");
|
fp = fopen(filename, "r");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
|
out_race:
|
||||||
/*
|
/*
|
||||||
* We raced with a task exiting - just return:
|
* 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);
|
snprintf(filename, sizeof(filename), "/proc/%d/task", pid);
|
||||||
|
|
||||||
tasks = opendir(filename);
|
tasks = opendir(filename);
|
||||||
|
if (tasks == NULL)
|
||||||
|
goto out_race;
|
||||||
|
|
||||||
while (!readdir_r(tasks, &dirent, &next) && next) {
|
while (!readdir_r(tasks, &dirent, &next) && next) {
|
||||||
char *end;
|
char *end;
|
||||||
pid = strtol(dirent.d_name, &end, 10);
|
pid = strtol(dirent.d_name, &end, 10);
|
||||||
|
|
Loading…
Reference in a new issue