public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Han Pingtian <hanpt@linux.vnet.ibm.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] waitpid/waitpid11: break test if fork() failed
Date: Fri, 15 Apr 2016 16:08:59 +0800	[thread overview]
Message-ID: <20160415080859.GA26131@localhost.localdomain> (raw)

Please review this patch. Thanks.


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

Signed-off-by: Han Pingtian <hanpt@linux.vnet.ibm.com>
---
 testcases/kernel/syscalls/waitpid/waitpid11.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/testcases/kernel/syscalls/waitpid/waitpid11.c b/testcases/kernel/syscalls/waitpid/waitpid11.c
index 4b662d5..af5b962 100644
--- a/testcases/kernel/syscalls/waitpid/waitpid11.c
+++ b/testcases/kernel/syscalls/waitpid/waitpid11.c
@@ -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)
-- 
1.9.3


             reply	other threads:[~2016-04-15  8:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-15  8:08 Han Pingtian [this message]
2016-04-20 11:45 ` [LTP] [PATCH] waitpid/waitpid11: break test if fork() failed Cyril Hrubis

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=20160415080859.GA26131@localhost.localdomain \
    --to=hanpt@linux.vnet.ibm.com \
    --cc=ltp@lists.linux.it \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox