Skip to contentSkip to conversation

waitpid/waitpid03: break test if fork failed

PATCH New Han Pingtian 2 participants 8 messages Apr 12, 2016 – Apr 19, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 waitpid/waitpid03: break test if fork failed

If continue after the fork failure, a lot of processes may be killed by the kill() on line 125.

---
 testcases/kernel/syscalls/waitpid/waitpid03.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/waitpid/waitpid03.c +2 -1
index 2599a92..648870c 100644
@@ -106,7 +106,8 @@ int main(int argc, char **argv)
 				if (DEBUG)
 					tst_resm(TINFO, "child # %d", ikids);
 			} else if (pid[ikids] == -1) {
-				tst_resm(TFAIL, "cannot open fork #%d", ikids);
+				tst_brkm(TBROK|TERRNO, cleanup,
+					 "cannot open fork #%d", ikids);
 			} else {
 #ifdef UCLINUX
 				if (self_exec(argv[0], "d", ikids) < 0) {
Signature · 1 line
1.9.3
#1 lore raw

PATCH 1/1 waitpid/waitpid03: break test if fork failed

Hi!

testcases/kernel/syscalls/waitpid/waitpid03.c int main(int argc, char **argv) · line 110

Quoted 3 lines
testcases/kernel/syscalls/waitpid/waitpid03.c +2 -1
-				tst_resm(TFAIL, "cannot open fork #%d", ikids);
+				tst_brkm(TBROK|TERRNO, cleanup,
+					 "cannot open fork #%d", ikids);

I guess that we should kill any of the allready sleeping children at this point.

If we move the pid[] array to be global we can create a kill_children() function to send a signal to all pids in pid[] that are > 0 and call it if fork fails with SIGKILL as well as from the main loop with the SIGTERM as well.

Signature · 2 lines
Cyril Hrubis
[email protected]
#2 lore raw

PATCH 1/1 waitpid/waitpid03: break test if fork failed

Quoted 7 lines · Cyril Hrubis

Hi!

Review

Quoted 3 lines
(quoted diff) +2 -1
-				tst_resm(TFAIL, "cannot open fork #%d", ikids);
+				tst_brkm(TBROK|TERRNO, cleanup,
+					 "cannot open fork #%d", ikids);

I guess that we should kill any of the allready sleeping children at this point.

Quoted 5 lines

If we move the pid[] array to be global we can create a kill_children() function to send a signal to all pids in pid[] that are > 0 and call it if fork fails with SIGKILL as well as from the main loop with the SIGTERM as well.

Thanks. How about this one? I think it is simple and enough for the purpose.

From 5ec101da361dae875fc3f9293cf4ec65be8bbb93 Mon Sep 17 00:00:00 2001
From: Han Pingtian <[email protected]>
Date: Tue, 12 Apr 2016 11:12:28 +0800
Subject: [PATCH] waitpid/waitpid03: break test if fork failed

If continue after the fork failure, a lot of processes may be killed by the kill() on line 125.

---
 testcases/kernel/syscalls/waitpid/waitpid03.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/waitpid/waitpid03.c +7 -1
index 2599a92..ba4be50 100644
@@ -106,7 +106,13 @@ int main(int argc, char **argv)
 				if (DEBUG)
 					tst_resm(TINFO, "child # %d", ikids);
 			} else if (pid[ikids] == -1) {
-				tst_resm(TFAIL, "cannot open fork #%d", ikids);
+				int i;
+
+				for (i = 1; i < ikids; i++)
+					kill(pid[i], 9);
+
+				tst_brkm(TBROK|TERRNO, cleanup,
+					 "cannot open fork #%d", ikids);
 			} else {
 #ifdef UCLINUX
 				if (self_exec(argv[0], "d", ikids) < 0) {
Signature · 1 line
1.9.3
#3 lore raw

PATCH 1/1 waitpid/waitpid03: break test if fork failed

Hi!

testcases/kernel/syscalls/waitpid/waitpid03.c int main(int argc, char **argv) · line 115

Quoted 8 lines
testcases/kernel/syscalls/waitpid/waitpid03.c +7 -1
-				tst_resm(TFAIL, "cannot open fork #%d", ikids);
+				int i;
+
+				for (i = 1; i < ikids; i++)
+					kill(pid[i], 9);
+
+				tst_brkm(TBROK|TERRNO, cleanup,
+					 "cannot open fork #%d", ikids);

The problem is that the errno may get clobbered by the call to the kill().

Signature · 2 lines
Cyril Hrubis
[email protected]
#4 lore raw

PATCH 1/1 waitpid/waitpid03: break test if fork failed

In reply to Cyril Hrubis
Quoted 7 lines · Cyril Hrubis

Hi!

Review

Quoted 3 lines
(quoted diff) +2 -1
-				tst_resm(TFAIL, "cannot open fork #%d", ikids);
+				tst_brkm(TBROK|TERRNO, cleanup,
+					 "cannot open fork #%d", ikids);

I guess that we should kill any of the allready sleeping children at this point.

Quoted 5 lines

If we move the pid[] array to be global we can create a kill_children() function to send a signal to all pids in pid[] that are > 0 and call it if fork fails with SIGKILL as well as from the main loop with the SIGTERM as well.

I think this one is better, please have a look. Thanks.

From aff8c1decee88bae37a8460ddce8d10a7a8f3d1a Mon Sep 17 00:00:00 2001
From: Han Pingtian <[email protected]>
Date: Tue, 12 Apr 2016 11:12:28 +0800
Subject: [PATCH] waitpid/waitpid03: break test if fork failed

If continue after the fork failure, a lot of processes may be killed by the kill() on line 125.

---
 testcases/kernel/syscalls/waitpid/waitpid03.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/waitpid/waitpid03.c +10 -1
index 2599a92..7e9d45c 100644
@@ -106,7 +106,16 @@ int main(int argc, char **argv)
 				if (DEBUG)
 					tst_resm(TINFO, "child # %d", ikids);
 			} else if (pid[ikids] == -1) {
-				tst_resm(TFAIL, "cannot open fork #%d", ikids);
+				int i;
+
+				tst_resm(TBROK|TERRNO, "cannot open fork #%d",
+					 ikids);
+
+				for (i = 1; i < ikids; i++)
+					kill(pid[i], 9);
+
+				cleanup();
+				tst_exit();
 			} else {
 #ifdef UCLINUX
 				if (self_exec(argv[0], "d", ikids) < 0) {
Signature · 1 line
1.9.3
#5 lore raw

PATCH 1/1 waitpid/waitpid03: break test if fork failed

Hi!

Quoted 14 lines
---
 testcases/kernel/syscalls/waitpid/waitpid03.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/waitpid/waitpid03.c +0 -1
index 2599a92..7e9d45c 100644
@@ -106,7 +106,16 @@ int main(int argc, char **argv)
 				if (DEBUG)
 					tst_resm(TINFO, "child # %d", ikids);
 			} else if (pid[ikids] == -1) {
-				tst_resm(TFAIL, "cannot open fork #%d", ikids);

testcases/kernel/syscalls/waitpid/waitpid03.c int main(int argc, char **argv) · line 118

Quoted 10 lines
testcases/kernel/syscalls/waitpid/waitpid03.c +10 -0
+				int i;
+
+				tst_resm(TBROK|TERRNO, "cannot open fork #%d",
+					 ikids);
+
+				for (i = 1; i < ikids; i++)
+					kill(pid[i], 9);
+
+				cleanup();
+				tst_exit();

This one is ugly. Why don't we kill the children in the test cleanup() here as well. This should be easy, just store the number of allready forked kids in a global variable and reset it to zero right after they were killed in the main loop.

Signature · 2 lines
Cyril Hrubis
[email protected]
#6 lore raw

PATCH 1/1 waitpid/waitpid03: break test if fork failed

Quoted 22 lines · Cyril Hrubis

Hi!

Quoted 21 lines
---
 testcases/kernel/syscalls/waitpid/waitpid03.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/waitpid/waitpid03.c +7 -1
index 2599a92..7e9d45c 100644
@@ -106,7 +106,16 @@ int main(int argc, char **argv)
 				if (DEBUG)
 					tst_resm(TINFO, "child # %d", ikids);
 			} else if (pid[ikids] == -1) {
-				tst_resm(TFAIL, "cannot open fork #%d", ikids);
+				int i;
+
+				tst_resm(TBROK|TERRNO, "cannot open fork #%d",
+					 ikids);
+
+				for (i = 1; i < ikids; i++)
+					kill(pid[i], 9);
Quoted 9 lines

testcases/kernel/syscalls/waitpid/waitpid03.c int main(int argc, char **argv) · line 118

Quoted 3 lines
testcases/kernel/syscalls/waitpid/waitpid03.c +3 -0
+
+				cleanup();
+				tst_exit();

This one is ugly. Why don't we kill the children in the test cleanup() here as well. This should be easy, just store the number of allready forked kids in a global variable and reset it to zero right after they were killed in the main loop.

Thanks. Please reveiw this new patch.

From 8b7c289ac51ec2e169bbe0147d4c1c3d1f08aa0b Mon Sep 17 00:00:00 2001
From: Han Pingtian <[email protected]>
Date: Tue, 12 Apr 2016 11:12:28 +0800
Subject: [PATCH] waitpid/waitpid03: break test if fork failed

If continue after the fork failure, a lot of processes may be killed by the kill() on line 125.

---
 testcases/kernel/syscalls/waitpid/waitpid03.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/waitpid/waitpid03.c +9 -3
index 2599a92..4b3f7a7 100644
@@ -64,6 +64,8 @@ int TST_TOTAL = 1;
 
 #define	MAXUPRC	25
 
+static int ikids;
+static int pid[MAXUPRC];
 static int condition_number;
 
 #ifdef UCLINUX
@@ -75,7 +77,7 @@ int main(int argc, char **argv)
 {
 	int lc;
 
-	int status, pid[25], ret;
+	int status, ret;
 
 	tst_parse_opts(argc, argv, NULL, NULL);
 #ifdef UCLINUX
@@ -87,7 +89,6 @@ int main(int argc, char **argv)
 	/* check for looping state if -i option is given */
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		/* reset tst_count in case we are looping */
-		int ikids = 0;
 		tst_count = 0;
 
 		/*
@@ -106,7 +107,9 @@ int main(int argc, char **argv)
 				if (DEBUG)
 					tst_resm(TINFO, "child # %d", ikids);
 			} else if (pid[ikids] == -1) {
-				tst_resm(TFAIL, "cannot open fork #%d", ikids);
+				tst_brkm(TBROK|TERRNO, cleanup, "cannot open "
+					"fork #%d", ikids);
+
 			} else {
 #ifdef UCLINUX
 				if (self_exec(argv[0], "d", ikids) < 0) {
@@ -125,6 +128,7 @@ int main(int argc, char **argv)
 			kill(pid[ikids], 15);
 		}
 
+		ikids = 0;
 		condition_number = 1;
 
 		/* Wait on one specific child */
@@ -185,4 +189,6 @@ static void setup(void)
 
 static void cleanup(void)
 {
+	while (ikids-- > 1)
+		kill(pid[ikids], 9);
 }
Signature · 1 line
1.9.3
#7 lore raw

PATCH 1/1 waitpid/waitpid03: break test if fork failed

Hi!

testcases/kernel/syscalls/waitpid/waitpid03.c static void setup(void) · line 193

Quoted 2 lines
testcases/kernel/syscalls/waitpid/waitpid03.c +2 -0
+	while (ikids-- > 1)
+		kill(pid[ikids], 9);

I've changed the number to a signal constat i.e. 9 -> SIGKILL and pushed, thanks.

Signature · 2 lines
Cyril Hrubis
[email protected]