Skip to contentSkip to conversation

waitpid/waitpid11: break test if fork() failed

PATCH New Han Pingtian 2 participants 2 messages Apr 15, 2016 – Apr 20, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 waitpid/waitpid11: break test if fork() failed

Please review this patch. Thanks.

Or the kill() will kill a lot of processes when -1 passed to it as pid.

---
 testcases/kernel/syscalls/waitpid/waitpid11.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/waitpid/waitpid11.c +13 -3
index 4b662d5..af5b962 100644
@@ -64,13 +64,14 @@ static void do_exit_uclinux(void);
 #endif
 
 static int fail;
+static int fork_kid_pid[MAXKIDS]; 
 
 int main(int ac, char **av)
 {
 	int kid_count, ret_val, status;
 	int i, j, k, found;
 	int group1, group2;
-	int fork_kid_pid[MAXKIDS], wait_kid_pid[MAXKIDS];
+	int wait_kid_pid[MAXKIDS];
 	int pid;
 
 	tst_parse_opts(ac, av, NULL, NULL);
@@ -130,8 +131,8 @@ int main(int ac, char **av)
 		}
 
 		if (ret_val < 0)
-			tst_resm(TFAIL, "Fork kid %d failed. errno = "
-				 "%d", kid_count, errno);
+			tst_brkm(TBROK|TERRNO, cleanup, "Fork kid %d failed",
+				 kid_count);
 
 		/* parent */
 		fork_kid_pid[kid_count] = ret_val;
@@ -259,6 +260,9 @@ int main(int ac, char **av)
 			fail = 1;
 		}
 	}
+
+	memset(fork_kid_pid, 0, sizeof(fork_kid_pid));
+
 	if (kid_count != (MAXKIDS / 2)) {
 		tst_resm(TFAIL, "Wrong number of children waited on "
 			 "for pid = 0");
@@ -271,6 +275,7 @@ int main(int ac, char **av)
 	else
 		tst_resm(TPASS, "Test PASSED");
 
+	cleanup();
 	tst_exit();
 }
 
@@ -287,6 +292,11 @@ static void setup(void)
 
 static void cleanup(void)
 {
+	int i;
+
+	for (i = 0; i < MAXKIDS; i++)
+		if (fork_kid_pid[i] > 0)
+			kill(fork_kid_pid[i], 9);
 }
 
 static void inthandlr(void)
Signature · 1 line
1.9.3
#1 lore raw

PATCH 1/1 waitpid/waitpid11: break test if fork() failed

Hi!

Quoted 2 lines

static int fail;
+static int fork_kid_pid[MAXKIDS];

^
Trailing whitespace. Please make sure not to add these.

I've also removed the call to cleanup() on line 104 in the test parent since the whole test is done in it's child and the cleanup is done in the child as well.

Pushed, thanks.

Signature · 2 lines
Cyril Hrubis
[email protected]