Re: [PATCH v3 13/54] tests/qtest: ide-test: Avoid using hardcoded /tmp

2022-09-26 Thread Marc-André Lureau
On Sun, Sep 25, 2022 at 3:56 PM Bin Meng  wrote:

> From: Bin Meng 
>
> 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 
>

Reviewed-by: Marc-André Lureau 



> ---
>
> Changes in v3:
> - Split to a separate patch
>
>  tests/qtest/ide-test.c | 10 ++
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/tests/qtest/ide-test.c b/tests/qtest/ide-test.c
> index 5bcb75a7e5..25302be6dc 100644
> --- a/tests/qtest/ide-test.c
> +++ b/tests/qtest/ide-test.c
> @@ -121,8 +121,8 @@ enum {
>  static QPCIBus *pcibus = NULL;
>  static QGuestAllocator guest_malloc;
>
> -static char tmp_path[] = "/tmp/qtest.XX";
> -static char debug_path[] = "/tmp/qtest-blkdebug.XX";
> +static char *tmp_path;
> +static char *debug_path;
>
>  static QTestState *ide_test_start(const char *cmdline_fmt, ...)
>  {
> @@ -1015,12 +1015,12 @@ int main(int argc, char **argv)
>  int ret;
>
>  /* Create temporary blkdebug instructions */
> -fd = mkstemp(debug_path);
> +fd = g_file_open_tmp("qtest-blkdebug.XX", _path, NULL);
>  g_assert(fd >= 0);
>  close(fd);
>
>  /* Create a temporary raw image */
> -fd = mkstemp(tmp_path);
> +fd = g_file_open_tmp("qtest.XX", _path, NULL);
>  g_assert(fd >= 0);
>  ret = ftruncate(fd, TEST_IMAGE_SIZE);
>  g_assert(ret == 0);
> @@ -1049,7 +1049,9 @@ int main(int argc, char **argv)
>
>  /* Cleanup */
>  unlink(tmp_path);
> +g_free(tmp_path);
>  unlink(debug_path);
> +g_free(debug_path);
>
>  return ret;
>  }
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau


[PATCH v3 13/54] tests/qtest: ide-test: Avoid using hardcoded /tmp

2022-09-25 Thread Bin Meng
From: Bin Meng 

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 
---

Changes in v3:
- Split to a separate patch

 tests/qtest/ide-test.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/tests/qtest/ide-test.c b/tests/qtest/ide-test.c
index 5bcb75a7e5..25302be6dc 100644
--- a/tests/qtest/ide-test.c
+++ b/tests/qtest/ide-test.c
@@ -121,8 +121,8 @@ enum {
 static QPCIBus *pcibus = NULL;
 static QGuestAllocator guest_malloc;
 
-static char tmp_path[] = "/tmp/qtest.XX";
-static char debug_path[] = "/tmp/qtest-blkdebug.XX";
+static char *tmp_path;
+static char *debug_path;
 
 static QTestState *ide_test_start(const char *cmdline_fmt, ...)
 {
@@ -1015,12 +1015,12 @@ int main(int argc, char **argv)
 int ret;
 
 /* Create temporary blkdebug instructions */
-fd = mkstemp(debug_path);
+fd = g_file_open_tmp("qtest-blkdebug.XX", _path, NULL);
 g_assert(fd >= 0);
 close(fd);
 
 /* Create a temporary raw image */
-fd = mkstemp(tmp_path);
+fd = g_file_open_tmp("qtest.XX", _path, NULL);
 g_assert(fd >= 0);
 ret = ftruncate(fd, TEST_IMAGE_SIZE);
 g_assert(ret == 0);
@@ -1049,7 +1049,9 @@ int main(int argc, char **argv)
 
 /* Cleanup */
 unlink(tmp_path);
+g_free(tmp_path);
 unlink(debug_path);
+g_free(debug_path);
 
 return ret;
 }
-- 
2.34.1