Skip to contentSkip to conversation

perf-record: Check correct pid when forking

PATCH In review Borislav Petkov 2 participants 4 messages May 31, 2010 – Jun 1, 2010 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf-record: Check correct pid when forking

When forking the child to be traced, we should check the correct return value from fork() and not a local variable which is otherwise unused.

---
 tools/perf/builtin-record.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
tools/perf/builtin-record.c +1 -2
index 9bc8905..dc3435e 100644
@@ -503,7 +503,6 @@ static int __cmd_record(int argc, const char **argv)
 {
 	int i, counter;
 	struct stat st;
-	pid_t pid = 0;
 	int flags;
 	int err;
 	unsigned long waking = 0;
@@ -572,7 +571,7 @@ static int __cmd_record(int argc, const char **argv)
 
 	if (forks) {
 		child_pid = fork();
-		if (pid < 0) {
+		if (child_pid < 0) {
 			perror("failed to fork");
 			exit(-1);
 		}
Signature · 6 lines
1.7.1


-- 
Regards/Gruss,
    Boris.
#1 lore raw
Quoted 21 lines · Borislav Petkov

When forking the child to be traced, we should check the correct return value from fork() and not a local variable which is otherwise unused.

---
 tools/perf/builtin-record.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
tools/perf/builtin-record.c +0 -1
index 9bc8905..dc3435e 100644
@@ -503,7 +503,6 @@ static int __cmd_record(int argc, const char **argv)
 {
 	int i, counter;
 	struct stat st;
-	pid_t pid = 0;
 	int flags;
 	int err;
 	unsigned long waking = 0;

tools/perf/builtin-record.c static int __cmd_record(int argc, const char **argv) · line 574

Quoted 5 lines
tools/perf/builtin-record.c +1 -1
@@ -572,7 +571,7 @@ static int __cmd_record(int argc, const char **argv)
 
 	if (forks) {
 		child_pid = fork();
-		if (pid < 0) {
+		if (child_pid < 0) {

Oops :)

Since I'm preparing some fixes for .35 in perf tools, I'm queuing this one too.

Thanks.

#2 lore raw

From: Frederic Weisbecker <[email protected]>
Date: Mon, May 31, 2010 at 11:27:26PM +0200

Hi Frederic :),

Quoted 23 lines · Borislav Petkov
Quoted 22 lines

When forking the child to be traced, we should check the correct return value from fork() and not a local variable which is otherwise unused.

---
 tools/perf/builtin-record.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
tools/perf/builtin-record.c +0 -1
index 9bc8905..dc3435e 100644
@@ -503,7 +503,6 @@ static int __cmd_record(int argc, const char **argv)
 {
 	int i, counter;
 	struct stat st;
-	pid_t pid = 0;
 	int flags;
 	int err;
 	unsigned long waking = 0;
@@ -572,7 +571,7 @@ static int __cmd_record(int argc, const char **argv)
 
Quoted 8 lines

tools/perf/builtin-record.c static int __cmd_record(int argc, const char **argv) · line 574

Quoted 4 lines
tools/perf/builtin-record.c +1 -1
 	if (forks) {
 		child_pid = fork();
-		if (pid < 0) {
+		if (child_pid < 0) {

Oops :)

Yeah, this looked really odd and I had recheck it couple of times just to be sure I'm not missing any "hidden" semantics. And it seems that nobody has hit that because obviously we always fork fine :)

Signature · 2 lines
Regards/Gruss,
    Boris.
#3 lore raw
In reply to Borislav Petkov
Commit-ID:  2fb750e825b5347de0390315f4284f13709a9856
Gitweb:     http://git.kernel.org/tip/2fb750e825b5347de0390315f4284f13709a9856
Author:     Borislav Petkov <[email protected]>
AuthorDate: Mon, 31 May 2010 23:18:18 +0200
Committer:  Frederic Weisbecker <[email protected]>
CommitDate: Tue, 1 Jun 2010 00:57:14 +0200

perf-record: Check correct pid when forking

When forking the child to be traced, we should check the correct return value from fork() and not a local variable which is otherwise unused.

Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Tom Zanussi <[email protected]>
Cc Stephane Eranian <[email protected]>

LKML-Reference: <[email protected]>

---
 tools/perf/builtin-record.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
tools/perf/builtin-record.c +1 -2
index 9bc8905..dc3435e 100644
@@ -503,7 +503,6 @@ static int __cmd_record(int argc, const char **argv)
 {
 	int i, counter;
 	struct stat st;
-	pid_t pid = 0;
 	int flags;
 	int err;
 	unsigned long waking = 0;
@@ -572,7 +571,7 @@ static int __cmd_record(int argc, const char **argv)
 
 	if (forks) {
 		child_pid = fork();
-		if (pid < 0) {
+		if (child_pid < 0) {
 			perror("failed to fork");
 			exit(-1);
 		}