diff mbox series

[05/51] tcg: Avoid using hardcoded /tmp

Message ID 20220824094029.1634519-6-bmeng.cn@gmail.com (mailing list archive)
State New, archived
Headers show
Series tests/qtest: Enable running qtest on Windows | expand

Commit Message

Bin Meng Aug. 24, 2022, 9:39 a.m. UTC
From: Bin Meng <bin.meng@windriver.com>

Use g_get_tmp_dir() to get the directory to use for temporary files.

Signed-off-by: Bin Meng <bin.meng@windriver.com>
---

 tcg/tcg.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Marc-André Lureau Aug. 31, 2022, 1:02 p.m. UTC | #1
Hi

On Wed, Aug 24, 2022 at 2:06 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> Use g_get_tmp_dir() to get the directory to use for temporary files.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
>  tcg/tcg.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/tcg/tcg.c b/tcg/tcg.c
> index 0f9cfe96f2..932156a352 100644
> --- a/tcg/tcg.c
> +++ b/tcg/tcg.c
> @@ -4729,13 +4729,15 @@ static void tcg_register_jit_int(const void
> *buf_ptr, size_t buf_size,
>      /* Enable this block to be able to debug the ELF image file creation.
>         One can use readelf, objdump, or other inspection utilities.  */
>      {
> -        FILE *f = fopen("/tmp/qemu.jit", "w+b");
> +        char *jit = g_strdup_printf("%s/qemu.jit", g_get_tmp_dir());
> +        FILE *f = fopen(jit, "w+b");
>

(this is only enabled if DEBUG_JIT)

Why not? you may also use g_autofree to avoid the call to g_free() below if
you respin.

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>



>          if (f) {
>              if (fwrite(img, img_size, 1, f) != img_size) {
>                  /* Avoid stupid unused return value warning for fwrite.
> */
>              }
>              fclose(f);
>          }
> +        g_free(jit);
>      }
>  #endif
>
> --
> 2.34.1
>
>
>
diff mbox series

Patch

diff --git a/tcg/tcg.c b/tcg/tcg.c
index 0f9cfe96f2..932156a352 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -4729,13 +4729,15 @@  static void tcg_register_jit_int(const void *buf_ptr, size_t buf_size,
     /* Enable this block to be able to debug the ELF image file creation.
        One can use readelf, objdump, or other inspection utilities.  */
     {
-        FILE *f = fopen("/tmp/qemu.jit", "w+b");
+        char *jit = g_strdup_printf("%s/qemu.jit", g_get_tmp_dir());
+        FILE *f = fopen(jit, "w+b");
         if (f) {
             if (fwrite(img, img_size, 1, f) != img_size) {
                 /* Avoid stupid unused return value warning for fwrite.  */
             }
             fclose(f);
         }
+        g_free(jit);
     }
 #endif