[CRIU] [PATCH 5/6] zdtm: get a test file name from arguments

Andrey Vagin avagin at openvz.org
Fri Jan 18 14:51:13 EST 2013


Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 test/zdtm/live/static/Makefile       |  4 ++--
 test/zdtm/live/static/file_locks00.c | 14 ++++++++++----
 test/zdtm/live/static/file_locks01.c | 19 +++++++++++++------
 3 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index f859ff6..b2d3366 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -83,8 +83,6 @@ TST_NOFILE	=				\
 		cow00				\
 		child_opened_proc		\
 		posix_timers			\
-		file_locks00		\
-		file_locks01		\
 #		jobctl00			\
 
 TST_FILE	=				\
@@ -114,6 +112,8 @@ TST_FILE	=				\
 		fdt_shared			\
 		sockets00			\
 		sockets_dgram			\
+		file_locks00			\
+		file_locks01			\
 
 TST_DIR		=				\
 		cwd00				\
diff --git a/test/zdtm/live/static/file_locks00.c b/test/zdtm/live/static/file_locks00.c
index 77d9e0b..9c559a8 100644
--- a/test/zdtm/live/static/file_locks00.c
+++ b/test/zdtm/live/static/file_locks00.c
@@ -8,14 +8,18 @@
 #include <sys/file.h>
 #include <sys/wait.h>
 #include <string.h>
+#include <linux/limits.h>
 
 #include "zdtmtst.h"
 
 const char *test_doc	= "Check that posix flocks are restored";
 const char *test_author	= "Qiang Huang <h.huangqiang at huawei.com>";
 
-char file0[] = "/tmp/zdtm_file_locks_XXXXXX";
-char file1[] = "/tmp/zdtm_file_locks_XXXXXX";
+char *filename;
+TEST_OPTION(filename, string, "file name", 1);
+
+char file0[PATH_MAX];
+char file1[PATH_MAX];
 
 static int lock_reg(int fd, int cmd, int type, int whence,
 		off_t offset, off_t len)
@@ -130,13 +134,15 @@ int main(int argc, char **argv)
 
 	test_init(argc, argv);
 
-	fd_0 = mkstemp(file0);
+	snprintf(file0, sizeof(file0), "%s.0", filename);
+	snprintf(file1, sizeof(file0), "%s.1", filename);
+	fd_0 = open(file0, O_RDWR | O_CREAT | O_EXCL, 0666);
 	if (fd_0 < 0) {
 		err("Unable to open file %s", file0);
 		return -1;
 	}
 
-	fd_1 = mkstemp(file1);
+	fd_1 = open(file1, O_RDWR | O_CREAT | O_EXCL, 0666);
 	if (fd_1 < 0) {
 		close(fd_0);
 		unlink(file0);
diff --git a/test/zdtm/live/static/file_locks01.c b/test/zdtm/live/static/file_locks01.c
index 958e523..d5274f7 100644
--- a/test/zdtm/live/static/file_locks01.c
+++ b/test/zdtm/live/static/file_locks01.c
@@ -6,25 +6,32 @@
 #include <unistd.h>
 #include <sys/file.h>
 #include <string.h>
+#include <linux/limits.h>
 
 #include "zdtmtst.h"
 
 const char *test_doc	= "Check that flock locks are restored";
 const char *test_author	= "Qiang Huang <h.huangqiang at huawei.com>";
 
-char file0[] = "/tmp/zdtm_file_locks_XXXXXX";
-char file1[] = "/tmp/zdtm_file_locks_XXXXXX";
-char file2[] = "/tmp/zdtm_file_locks_XXXXXX";
+char *filename;
+TEST_OPTION(filename, string, "file name", 1);
+
+char file0[PATH_MAX];
+char file1[PATH_MAX];
+char file2[PATH_MAX];
 
 static int open_all_files(int *fd_0, int *fd_1, int *fd_2)
 {
-	*fd_0 = mkstemp(file0);
+	snprintf(file0, sizeof(file0), "%s.0", filename);
+	snprintf(file1, sizeof(file0), "%s.1", filename);
+	snprintf(file2, sizeof(file0), "%s.2", filename);
+	*fd_0 = open(file0, O_RDWR | O_CREAT | O_EXCL, 0666);
 	if (*fd_0 < 0) {
 		err("Unable to open file %s", file0);
 		return -1;
 	}
 
-	*fd_1 = mkstemp(file1);
+	*fd_1 = open(file1, O_RDWR | O_CREAT | O_EXCL, 0666);
 	if (*fd_1 < 0) {
 		close(*fd_0);
 		unlink(file0);
@@ -32,7 +39,7 @@ static int open_all_files(int *fd_0, int *fd_1, int *fd_2)
 		return -1;
 	}
 
-	*fd_2 = mkstemp(file2);
+	*fd_2 = open(file2, O_RDWR | O_CREAT | O_EXCL, 0666);
 	if (*fd_2 < 0) {
 		close(*fd_0);
 		close(*fd_1);
-- 
1.7.11.7



More information about the CRIU mailing list