[4/5] fown: test -- Update file_own_dead to test O_PATH case

Submitted by Cyrill Gorcunov on Dec. 7, 2018, 12:29 p.m.

Details

Message ID 20181207122948.26683-5-gorcunov@gmail.com
State New
Series "fown: Handle dead pids and O_PATH"
Headers show

Commit Message

Cyrill Gorcunov Dec. 7, 2018, 12:29 p.m.
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
---
 test/zdtm/static/Makefile         |  2 +-
 test/zdtm/static/file_fown_dead.c | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index ab20c61b3574..2d7bd9c7bc5b 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -119,7 +119,6 @@  TST_NOFILE	:=				\
 		groups				\
 		pdeath_sig			\
 		file_fown			\
-		file_fown_dead			\
 		proc-self			\
 		eventfs00			\
 		epoll				\
@@ -279,6 +278,7 @@  TST_FILE	=				\
 		netns-nf			\
 		maps_file_prot			\
 		socket_close_data01		\
+		file_fown_dead			\
 
 TST_DIR		=				\
 		cwd00				\
diff --git a/test/zdtm/static/file_fown_dead.c b/test/zdtm/static/file_fown_dead.c
index 3a99bc729f51..92c6d0ad9dc7 100644
--- a/test/zdtm/static/file_fown_dead.c
+++ b/test/zdtm/static/file_fown_dead.c
@@ -22,6 +22,9 @@ 
 const char *test_doc	= "Check for restore with dead file owners";
 const char *test_author	= "Cyrill Gorcunov <gorcunov@openvz.org>";
 
+char *filename;
+TEST_OPTION(filename, string, "file name", 1);
+
 struct params {
 	int	sigio;
 	int	pipe_flags[2];
@@ -81,9 +84,23 @@  int main(int argc, char *argv[])
 	uid_t ruid, euid, suid;
 	int status, pipes[2];
 	pid_t pid;
+	int fd;
 
 	test_init(argc, argv);
 
+	fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0644);
+	if (fd < 0) {
+		pr_perror("Can't create %s", filename);
+		exit(1);
+	}
+	close(fd);
+
+	fd = open(filename, O_PATH, 0644);
+	if (fd < 0) {
+		pr_perror("Can't open %s as O_PATH", filename);
+		exit(1);
+	}
+
 	shared = (void *)mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
 	if ((void *)shared == MAP_FAILED) {
 		fail("mmap failed");
@@ -187,6 +204,8 @@  int main(int argc, char *argv[])
 		exit(1);
 	}
 
+	close(fd);
+
 	pass();
 	return 0;
 }

Comments

Andrei Vagin Dec. 11, 2018, 6:21 a.m.
On Fri, Dec 07, 2018 at 03:29:47PM +0300, Cyrill Gorcunov wrote:
> Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
> ---
>  test/zdtm/static/Makefile         |  2 +-
>  test/zdtm/static/file_fown_dead.c | 19 +++++++++++++++++++
>  2 files changed, 20 insertions(+), 1 deletion(-)
> 
> diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
> index ab20c61b3574..2d7bd9c7bc5b 100644
> --- a/test/zdtm/static/Makefile
> +++ b/test/zdtm/static/Makefile
> @@ -119,7 +119,6 @@ TST_NOFILE	:=				\
>  		groups				\
>  		pdeath_sig			\
>  		file_fown			\
> -		file_fown_dead			\
>  		proc-self			\
>  		eventfs00			\
>  		epoll				\
> @@ -279,6 +278,7 @@ TST_FILE	=				\
>  		netns-nf			\
>  		maps_file_prot			\
>  		socket_close_data01		\
> +		file_fown_dead			\
>  
>  TST_DIR		=				\
>  		cwd00				\
> diff --git a/test/zdtm/static/file_fown_dead.c b/test/zdtm/static/file_fown_dead.c
> index 3a99bc729f51..92c6d0ad9dc7 100644
> --- a/test/zdtm/static/file_fown_dead.c
> +++ b/test/zdtm/static/file_fown_dead.c
> @@ -22,6 +22,9 @@
>  const char *test_doc	= "Check for restore with dead file owners";
>  const char *test_author	= "Cyrill Gorcunov <gorcunov@openvz.org>";
>  
> +char *filename;
> +TEST_OPTION(filename, string, "file name", 1);
> +
>  struct params {
>  	int	sigio;
>  	int	pipe_flags[2];
> @@ -81,9 +84,23 @@ int main(int argc, char *argv[])
>  	uid_t ruid, euid, suid;
>  	int status, pipes[2];
>  	pid_t pid;
> +	int fd;
>  
>  	test_init(argc, argv);
>  
> +	fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0644);
> +	if (fd < 0) {
> +		pr_perror("Can't create %s", filename);
> +		exit(1);
> +	}
> +	close(fd);
> +
> +	fd = open(filename, O_PATH, 0644);

Could you create another test for O_PATH?

> +	if (fd < 0) {
> +		pr_perror("Can't open %s as O_PATH", filename);
> +		exit(1);
> +	}
> +
>  	shared = (void *)mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
>  	if ((void *)shared == MAP_FAILED) {
>  		fail("mmap failed");
> @@ -187,6 +204,8 @@ int main(int argc, char *argv[])
>  		exit(1);
>  	}
>  
> +	close(fd);
> +
>  	pass();
>  	return 0;
>  }
> -- 
> 2.17.2
>
Cyrill Gorcunov Dec. 11, 2018, 11:23 a.m.
On Mon, Dec 10, 2018 at 10:21:13PM -0800, Andrey Vagin wrote:
...
> > +
> > +	fd = open(filename, O_PATH, 0644);
> 
> Could you create another test for O_PATH?

Yes, will rework the series.