public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* Re: [LTP] [PATCH V2] userns02: add SAFE_CLOSE
  2015-06-16 22:26 [LTP] [PATCH V2] userns02: add SAFE_CLOSE Yuan Sun
@ 2015-06-16 14:39 ` Jan Stancek
  0 siblings, 0 replies; 2+ messages in thread
From: Jan Stancek @ 2015-06-16 14:39 UTC (permalink / raw)
  To: Yuan Sun; +Cc: ltp-list





----- Original Message -----
> From: "Yuan Sun" <sunyuan3@huawei.com>
> To: jstancek@redhat.com
> Cc: ltp-list@lists.sourceforge.net
> Sent: Wednesday, 17 June, 2015 12:26:55 AM
> Subject: [PATCH V2] userns02: add SAFE_CLOSE
> 
> Signed-off-by: Yuan Sun <sunyuan3@huawei.com>

Tested and applied.

Regards,
Jan

> ---
>  testcases/kernel/containers/userns/userns02.c | 22 ++++++++++++----------
>  1 file changed, 12 insertions(+), 10 deletions(-)
> 
> diff --git a/testcases/kernel/containers/userns/userns02.c
> b/testcases/kernel/containers/userns/userns02.c
> index ad5dda5..3bcb97d 100644
> --- a/testcases/kernel/containers/userns/userns02.c
> +++ b/testcases/kernel/containers/userns/userns02.c
> @@ -31,6 +31,11 @@
>  char *TCID = "user_namespace2";
>  int TST_TOTAL = 1;
>  
> +static void cleanup(void)
> +{
> +	tst_rmdir();
> +}
> +
>  /*
>   * child_fn1() - Inside a new user namespace
>   */
> @@ -62,11 +67,6 @@ static void setup(void)
>  	TST_CHECKPOINT_INIT(NULL);
>  }
>  
> -static void cleanup(void)
> -{
> -	tst_rmdir();
> -}
> -
>  int main(int argc, char *argv[])
>  {
>  	int status;
> @@ -93,14 +93,16 @@ int main(int argc, char *argv[])
>  		parentgid = getegid();
>  		sprintf(path, "/proc/%d/uid_map", childpid);
>  		sprintf(content, "100 %d 1", parentuid);
> -		fd = SAFE_OPEN(NULL, path, O_WRONLY, 0644);
> -		SAFE_WRITE(NULL, 1, fd, content, strlen(content));
> +		fd = SAFE_OPEN(cleanup, path, O_WRONLY, 0644);
> +		SAFE_WRITE(cleanup, 1, fd, content, strlen(content));
> +		SAFE_CLOSE(cleanup, fd);
>  		sprintf(path, "/proc/%d/gid_map", childpid);
>  		sprintf(content, "100 %d 1", parentgid);
> -		fd = SAFE_OPEN(NULL, path, O_WRONLY, 0644);
> -		SAFE_WRITE(NULL, 1, fd, content, strlen(content));
> +		fd = SAFE_OPEN(cleanup, path, O_WRONLY, 0644);
> +		SAFE_WRITE(cleanup, 1, fd, content, strlen(content));
> +		SAFE_CLOSE(cleanup, fd);
>  
> -		TST_SAFE_CHECKPOINT_WAKE(NULL, 0);
> +		TST_SAFE_CHECKPOINT_WAKE(cleanup, 0);
>  
>  		if (waitpid(childpid, &status, 0) < 0)
>  			tst_brkm(TBROK | TERRNO, cleanup, "waitpid failed");
> --
> 1.9.1
> 
> 

------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [LTP] [PATCH V2] userns02: add SAFE_CLOSE
@ 2015-06-16 22:26 Yuan Sun
  2015-06-16 14:39 ` Jan Stancek
  0 siblings, 1 reply; 2+ messages in thread
From: Yuan Sun @ 2015-06-16 22:26 UTC (permalink / raw)
  To: jstancek; +Cc: ltp-list

Signed-off-by: Yuan Sun <sunyuan3@huawei.com>
---
 testcases/kernel/containers/userns/userns02.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/testcases/kernel/containers/userns/userns02.c b/testcases/kernel/containers/userns/userns02.c
index ad5dda5..3bcb97d 100644
--- a/testcases/kernel/containers/userns/userns02.c
+++ b/testcases/kernel/containers/userns/userns02.c
@@ -31,6 +31,11 @@
 char *TCID = "user_namespace2";
 int TST_TOTAL = 1;
 
+static void cleanup(void)
+{
+	tst_rmdir();
+}
+
 /*
  * child_fn1() - Inside a new user namespace
  */
@@ -62,11 +67,6 @@ static void setup(void)
 	TST_CHECKPOINT_INIT(NULL);
 }
 
-static void cleanup(void)
-{
-	tst_rmdir();
-}
-
 int main(int argc, char *argv[])
 {
 	int status;
@@ -93,14 +93,16 @@ int main(int argc, char *argv[])
 		parentgid = getegid();
 		sprintf(path, "/proc/%d/uid_map", childpid);
 		sprintf(content, "100 %d 1", parentuid);
-		fd = SAFE_OPEN(NULL, path, O_WRONLY, 0644);
-		SAFE_WRITE(NULL, 1, fd, content, strlen(content));
+		fd = SAFE_OPEN(cleanup, path, O_WRONLY, 0644);
+		SAFE_WRITE(cleanup, 1, fd, content, strlen(content));
+		SAFE_CLOSE(cleanup, fd);
 		sprintf(path, "/proc/%d/gid_map", childpid);
 		sprintf(content, "100 %d 1", parentgid);
-		fd = SAFE_OPEN(NULL, path, O_WRONLY, 0644);
-		SAFE_WRITE(NULL, 1, fd, content, strlen(content));
+		fd = SAFE_OPEN(cleanup, path, O_WRONLY, 0644);
+		SAFE_WRITE(cleanup, 1, fd, content, strlen(content));
+		SAFE_CLOSE(cleanup, fd);
 
-		TST_SAFE_CHECKPOINT_WAKE(NULL, 0);
+		TST_SAFE_CHECKPOINT_WAKE(cleanup, 0);
 
 		if (waitpid(childpid, &status, 0) < 0)
 			tst_brkm(TBROK | TERRNO, cleanup, "waitpid failed");
-- 
1.9.1


------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-06-16 14:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-16 22:26 [LTP] [PATCH V2] userns02: add SAFE_CLOSE Yuan Sun
2015-06-16 14:39 ` Jan Stancek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox