qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] block: honor $TMPDIR in create_tmp_file()
@ 2025-08-31 11:48 Michael Tokarev
  2025-08-31 22:39 ` Richard Henderson
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Tokarev @ 2025-08-31 11:48 UTC (permalink / raw)
  To: qemu-devel, qemu-block; +Cc: Michael Tokarev, Bin Meng

Current code uses g_get_tmp_dir() to get temporary directory,
and if the returned *value* is "/tmp", the code changes it to
"/var/tmp".  This is wrong, - we should use "/var/tmp" only if
$TMPDIR is not set, not if it is set to some specific value.
In particular, the code doesn't let us to use TMPDIR=/tmp.

Fix this by using g_get_tmp_dir() only on windows platform as
before, and open-code $TMPDIR usage on everything else.
g_get_tmp_dir() checks $TMP and $TEMP too, but these variables
are windows-specific and should not be used on *nix.

Fixes: 69fbfff95e84 "block: Refactor get_tmp_filename()"
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1626
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
 block.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/block.c b/block.c
index 8848e9a7ed..f86fc9db35 100644
--- a/block.c
+++ b/block.c
@@ -853,8 +853,6 @@ char *create_tmp_file(Error **errp)
     const char *tmpdir;
     g_autofree char *filename = NULL;
 
-    tmpdir = g_get_tmp_dir();
-#ifndef _WIN32
     /*
      * See commit 69bef79 ("block: use /var/tmp instead of /tmp for -snapshot")
      *
@@ -862,7 +860,12 @@ char *create_tmp_file(Error **errp)
      * so the files can become very large. /tmp is often a tmpfs where as
      * /var/tmp is usually on a disk, so more appropriate for disk images.
      */
-    if (!g_strcmp0(tmpdir, "/tmp")) {
+
+#ifdef _WIN32
+    tmpdir = g_get_tmp_dir();
+#else
+    tmpdir = getenv("TMPDIR");
+    if (!tmpdir) {
         tmpdir = "/var/tmp";
     }
 #endif
-- 
2.47.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-09-02 16:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-31 11:48 [PATCH] block: honor $TMPDIR in create_tmp_file() Michael Tokarev
2025-08-31 22:39 ` Richard Henderson
2025-09-01  5:31   ` Michael Tokarev
2025-09-02 13:25     ` Richard Henderson
2025-09-02 16:16       ` Michael Tokarev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).