[LTP] [PATCH v3 7/9] Rewrite userns07.c using new LTP API

Cyril Hrubis chrubis@suse.cz
Tue Mar 29 16:27:28 CEST 2022


Hi!
Pushed with minor fixes, thanks.

- Rewrote the description to match what the test does better
- Got rid of the useless TEST() macro usage
- Fixed the tst_strstatus() usage
- Made use of the SAFE_FILE_PRINTF()

Full diff:

diff --git a/testcases/kernel/containers/userns/userns07.c b/testcases/kernel/containers/userns/userns07.c
index 454abedae..4659de636 100644
--- a/testcases/kernel/containers/userns/userns07.c
+++ b/testcases/kernel/containers/userns/userns07.c
@@ -7,8 +7,7 @@
 /*\
  * [Description]
  *
- * Verify that the kernel imposes a limit of at least 32 nested levels on
- * user namespaces.
+ * Verify that the kernel allows at least 32 nested levels of user namespaces.
  */
 
 #define _GNU_SOURCE
@@ -40,14 +39,12 @@ static int child_fn1(void *arg)
 		return 0;
 	}
 
-	TEST(ltp_clone_quick(CLONE_NEWUSER | SIGCHLD, (void *)child_fn1, (void *)(level + 1)));
-	if (TST_RET < 0) {
+	cpid1 = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD, (void *)child_fn1, (void *)(level + 1));
+	if (cpid1 < 0) {
 		tst_res(TFAIL | TERRNO, "level %ld, unexpected error", level);
 		return 1;
 	}
 
-	cpid1 = (int)TST_RET;
-
 	parentuid = geteuid();
 	parentgid = getegid();
 
@@ -58,10 +55,8 @@ static int child_fn1(void *arg)
 
 	SAFE_WAITPID(cpid1, &status, 0);
 
-	if (WIFEXITED(status) && WEXITSTATUS(status) != 0)
-		tst_brk(TBROK | TERRNO, "child exited abnormally %s", tst_strstatus(status));
-	else if (WIFSIGNALED(status))
-		tst_brk(TBROK | TERRNO, "child was killed with signal = %d", WTERMSIG(status));
+	if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+		tst_brk(TBROK, "child %s", tst_strstatus(status));
 
 	return 0;
 }
@@ -71,7 +66,6 @@ static void run(void)
 	pid_t cpid1;
 	int parentuid;
 	int parentgid;
-	int fd;
 	char path[BUFSIZ];
 
 	cpid1 = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD, (void *)child_fn1, (void *)0);
@@ -83,10 +77,7 @@ static void run(void)
 
 	if (access("/proc/self/setgroups", F_OK) == 0) {
 		sprintf(path, "/proc/%d/setgroups", cpid1);
-
-		fd = SAFE_OPEN(path, O_WRONLY, 0644);
-		SAFE_WRITE(1, fd, "deny", 4);
-		SAFE_CLOSE(fd);
+		SAFE_FILE_PRINTF(path, "deny");
 	}
 
 	updatemap(cpid1, UID_MAP, 0, parentuid);

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list