OSDN Git Service

tests/qtest: virtio-blk-test: Avoid using hardcoded /tmp
authorBin Meng <bin.meng@windriver.com>
Sun, 25 Sep 2022 11:29:57 +0000 (19:29 +0800)
committerThomas Huth <thuth@redhat.com>
Tue, 27 Sep 2022 18:51:20 +0000 (20:51 +0200)
This case was written to use hardcoded /tmp directory for temporary
files. Update to use g_file_open_tmp() for a portable implementation.

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20220925113032.1949844-20-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
tests/qtest/virtio-blk-test.c

index dc5eed3..19c01f8 100644 (file)
@@ -49,10 +49,10 @@ static void drive_destroy(void *path)
 static char *drive_create(void)
 {
     int fd, ret;
-    char *t_path = g_strdup("/tmp/qtest.XXXXXX");
+    char *t_path;
 
     /* Create a temporary raw image */
-    fd = mkstemp(t_path);
+    fd = g_file_open_tmp("qtest.XXXXXX", &t_path, NULL);
     g_assert_cmpint(fd, >=, 0);
     ret = ftruncate(fd, TEST_IMAGE_SIZE);
     g_assert_cmpint(ret, ==, 0);