summary refs log tree commit diff stats
path: root/tests/qtest/qmp-test.c
diff options
context:
space:
mode:
authorBin Meng <bin.meng@windriver.com>2022-09-27 19:05:54 +0800
committerThomas Huth <thuth@redhat.com>2022-09-27 20:51:21 +0200
commitc12fea71a0195b71715f4c1b190232bebb2e9cf6 (patch)
treea1057fc57f77ae89cd283e759358d5c0fa1650cb /tests/qtest/qmp-test.c
parent8189b27d3b183e27e3720f4a06b6d950542cba64 (diff)
downloadfocaccia-qemu-c12fea71a0195b71715f4c1b190232bebb2e9cf6.tar.gz
focaccia-qemu-c12fea71a0195b71715f4c1b190232bebb2e9cf6.zip
tests/qtest: qmp-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-17-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/qmp-test.c')
-rw-r--r--tests/qtest/qmp-test.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/tests/qtest/qmp-test.c b/tests/qtest/qmp-test.c
index 23b2a37942..22957fa49c 100644
--- a/tests/qtest/qmp-test.c
+++ b/tests/qtest/qmp-test.c
@@ -163,14 +163,15 @@ static void test_qmp_protocol(void)
 
 /* Out-of-band tests */
 
-char tmpdir[] = "/tmp/qmp-test-XXXXXX";
+char *tmpdir;
 char *fifo_name;
 
 static void setup_blocking_cmd(void)
 {
-    if (!g_mkdtemp(tmpdir)) {
-        g_error("g_mkdtemp: %s", strerror(errno));
-    }
+    GError *err = NULL;
+    tmpdir = g_dir_make_tmp("qmp-test-XXXXXX", &err);
+    g_assert_no_error(err);
+
     fifo_name = g_strdup_printf("%s/fifo", tmpdir);
     if (mkfifo(fifo_name, 0666)) {
         g_error("mkfifo: %s", strerror(errno));
@@ -181,6 +182,7 @@ static void cleanup_blocking_cmd(void)
 {
     unlink(fifo_name);
     rmdir(tmpdir);
+    g_free(tmpdir);
 }
 
 static void send_cmd_that_blocks(QTestState *s, const char *id)