[LTP] [PATCH v3 7/9] mmapstress01: use SAFE_FORK

Edward Liaw edliaw@google.com
Tue Oct 4 20:20:38 CEST 2022


Signed-off-by: Edward Liaw <edliaw@google.com>
---
 testcases/kernel/mem/mmapstress/mmapstress01.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/testcases/kernel/mem/mmapstress/mmapstress01.c b/testcases/kernel/mem/mmapstress/mmapstress01.c
index 7e8226700..99ab0d64e 100644
--- a/testcases/kernel/mem/mmapstress/mmapstress01.c
+++ b/testcases/kernel/mem/mmapstress/mmapstress01.c
@@ -227,12 +227,7 @@ static void run(void)
 	 *  Fork off mmap children.
 	 */
 	for (procno = 0; procno < nprocs; procno++) {
-		switch (pid = fork()) {
-
-		case -1:
-			tst_brk(TFAIL, "fork error");
-			break;
-
+		switch (pid = SAFE_FORK()) {
 		case 0:
 			child_mapper(TEST_FILE, (unsigned int)procno, (unsigned int)nprocs);
 			exit(0);
@@ -273,10 +268,8 @@ static void run(void)
 				tst_brk(TFAIL, "unknown child pid %d, <x%x>",
 					pid, wait_stat);
 
-			if ((pid = fork()) == -1) {
-				pidarray[i] = 0;
-				tst_brk(TFAIL, "fork error");
-			} else if (pid == 0) {	/* child */
+			pid = SAFE_FORK();
+			if (pid == 0) {	/* child */
 				child_mapper(TEST_FILE, (unsigned int)i, (unsigned int)nprocs);
 				exit(0);
 			} else {
@@ -485,4 +478,5 @@ static struct tst_test test = {
 	.options = options,
 	.cleanup = cleanup,
 	.needs_tmpdir = 1,
+	.forks_child = 1,
 };
-- 
2.38.0.rc1.362.ged0d419d3c-goog



More information about the ltp mailing list