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 <m...@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