summary refs log tree commit diff stats
path: root/tests/qtest/vhost-user-test.c
diff options
context:
space:
mode:
authorBin Meng <bin.meng@windriver.com>2022-09-27 19:05:56 +0800
committerThomas Huth <thuth@redhat.com>2022-09-27 20:51:21 +0200
commite6efe236c1d1f2451d59a7151c50d1c79360857c (patch)
treefbacaa1d08e20c3d2e2f86abe19c868006576a29 /tests/qtest/vhost-user-test.c
parentc12fea71a0195b71715f4c1b190232bebb2e9cf6 (diff)
downloadfocaccia-qemu-e6efe236c1d1f2451d59a7151c50d1c79360857c.tar.gz
focaccia-qemu-e6efe236c1d1f2451d59a7151c50d1c79360857c.zip
tests/qtest: vhost-user-test: Avoid using hardcoded /tmp
This case was written to use hardcoded /tmp directory for temporary
files. Update to use g_dir_make_tmp() for a portable implementation.

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Message-Id: <20220927110632.1973965-19-bmeng.cn@gmail.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Diffstat (limited to 'tests/qtest/vhost-user-test.c')
-rw-r--r--tests/qtest/vhost-user-test.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c
index d7d6cfc9bd..84498941a6 100644
--- a/tests/qtest/vhost-user-test.c
+++ b/tests/qtest/vhost-user-test.c
@@ -482,8 +482,8 @@ static TestServer *test_server_new(const gchar *name,
         struct vhost_user_ops *ops)
 {
     TestServer *server = g_new0(TestServer, 1);
-    char template[] = "/tmp/vhost-test-XXXXXX";
-    const char *tmpfs;
+    g_autofree const char *tmpfs = NULL;
+    GError *err = NULL;
 
     server->context = g_main_context_new();
     server->loop = g_main_loop_new(server->context, FALSE);
@@ -491,9 +491,11 @@ static TestServer *test_server_new(const gchar *name,
     /* run the main loop thread so the chardev may operate */
     server->thread = g_thread_new(NULL, thread_function, server->loop);
 
-    tmpfs = g_mkdtemp(template);
+    tmpfs = g_dir_make_tmp("vhost-test-XXXXXX", &err);
     if (!tmpfs) {
-        g_test_message("g_mkdtemp on path (%s): %s", template, strerror(errno));
+        g_test_message("g_dir_make_tmp on path (%s): %s", tmpfs,
+                       err->message);
+        g_error_free(err);
     }
     g_assert(tmpfs);