]> xenbits.xensource.com Git - qemu-xen.git/commitdiff
tests/qtest: qmp-test: Avoid using hardcoded /tmp
authorBin Meng <bin.meng@windriver.com>
Tue, 27 Sep 2022 11:05:54 +0000 (19:05 +0800)
committerThomas Huth <thuth@redhat.com>
Tue, 27 Sep 2022 18:51:21 +0000 (20:51 +0200)
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>
tests/qtest/qmp-test.c

index 23b2a379423235db6313978adf5cfeb35c465892..22957fa49c228dde9ce3e9c8d9b21079a81a3603 100644 (file)
@@ -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)