diff mbox series

[v1,8/8] Rewrite userns08.c using new LTP API

Message ID 20220211092646.23748-9-andrea.cervesato@suse.de
State Superseded
Headers show
Series Rewrite userns testing suite using new LTP API | expand

Commit Message

Andrea Cervesato Feb. 11, 2022, 9:26 a.m. UTC
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.de>
---
 testcases/kernel/containers/userns/userns08.c | 49 +++++++++----------
 1 file changed, 24 insertions(+), 25 deletions(-)
diff mbox series

Patch

diff --git a/testcases/kernel/containers/userns/userns08.c b/testcases/kernel/containers/userns/userns08.c
index c141b1aca..1935fcf11 100644
--- a/testcases/kernel/containers/userns/userns08.c
+++ b/testcases/kernel/containers/userns/userns08.c
@@ -17,6 +17,7 @@ 
  * by (the real) root. So on the second level we reset dumpable to 1.
  *
  */
+
 #define _GNU_SOURCE
 #include <stdio.h>
 #include <stdlib.h>
@@ -30,16 +31,12 @@ 
 
 static pid_t clone_newuser(void)
 {
-	const struct tst_clone_args cargs = {
-		CLONE_NEWUSER,
-		SIGCHLD
-	};
+	const struct tst_clone_args cargs = { CLONE_NEWUSER, SIGCHLD };
 
 	return SAFE_CLONE(&cargs);
 }
 
-static void write_mapping(const pid_t proc_in_ns,
-			  const char *const id_mapping)
+static void write_mapping(const pid_t proc_in_ns, const char *const id_mapping)
 {
 	char proc_path[PATH_MAX];
 	int proc_dir;
@@ -61,18 +58,19 @@  static void write_mapping(const pid_t proc_in_ns,
 static void ns_level2(void)
 {
 	if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0))
-		tst_res(TINFO | TERRNO, "Failed to set dumpable flag");
+		tst_brk(TBROK | TTERRNO, "Failed to set dumpable flag");
+
 	TST_CHECKPOINT_WAKE_AND_WAIT(1);
 
-	TST_EXP_FAIL(open("restricted", O_WRONLY), EACCES,
-		     "Denied write access to ./restricted");
+	TST_EXP_FAIL(open("restricted", O_WRONLY), EACCES, "Denied write access to ./restricted");
 
 	exit(0);
 }
 
 static void ns_level1(void)
 {
-	const char *const map_over_5 = "0 0 1\n1 1 1\n2 2 1\n3 3 1\n4 4 1\n5 5 990";
+	const char *const map_over_5 =
+		"0 0 1\n1 1 1\n2 2 1\n3 3 1\n4 4 1\n5 5 990";
 	pid_t level2_proc;
 
 	TST_CHECKPOINT_WAIT(0);
@@ -89,7 +87,6 @@  static void ns_level1(void)
 	write_mapping(level2_proc, map_over_5);
 
 	TST_CHECKPOINT_WAKE(1);
-	tst_reap_children();
 
 	exit(0);
 }
@@ -111,7 +108,6 @@  static void run(void)
 	write_mapping(level1_proc, "0 100000 1000");
 
 	TST_CHECKPOINT_WAKE(0);
-	tst_reap_children();
 }
 
 static void setup(void)
@@ -130,17 +126,20 @@  static struct tst_test test = {
 	.needs_checkpoints = 1,
 	.needs_root = 1,
 	.forks_child = 1,
-	.needs_kconfigs = (const char *[]) {
-		"CONFIG_USER_NS",
-		NULL
-	},
-	.save_restore = (const char * const[]) {
-		"?/proc/sys/user/max_user_namespaces",
-		NULL,
-	},
-	.tags = (const struct tst_tag[]) {
-		{"linux-git", "d2f007dbe7e4"},
-		{"CVE", "CVE-2018-18955"},
-		{}
-	},
+	.needs_kconfigs =
+		(const char *[]){
+			"CONFIG_USER_NS",
+			NULL,
+		},
+	.save_restore =
+		(const char *const[]){
+			"?/proc/sys/user/max_user_namespaces",
+			NULL,
+		},
+	.tags =
+		(const struct tst_tag[]){
+			{ "linux-git", "d2f007dbe7e4" },
+			{ "CVE", "CVE-2018-18955" },
+			{},
+		},
 };