[PATCH v3 11/26] util/qemu-sockets: Use g_get_tmp_dir() to get the directory for temporary files

Alex Bennée posted 26 patches 3 years, 3 months ago
Only 25 patches received!
[PATCH v3 11/26] util/qemu-sockets: Use g_get_tmp_dir() to get the directory for temporary files
Posted by Alex Bennée 3 years, 3 months ago
From: Bin Meng <bin.meng@windriver.com>

Replace the existing logic to get the directory for temporary files
with g_get_tmp_dir(), which works for win32 too.

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20221006151927.2079583-4-bmeng.cn@gmail.com>
---
 util/qemu-sockets.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 83f4bd6fd2..0c41ca9e42 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -919,9 +919,8 @@ static int unix_listen_saddr(UnixSocketAddress *saddr,
     if (saddr->path[0] || abstract) {
         path = saddr->path;
     } else {
-        const char *tmpdir = getenv("TMPDIR");
-        tmpdir = tmpdir ? tmpdir : "/tmp";
-        path = pathbuf = g_strdup_printf("%s/qemu-socket-XXXXXX", tmpdir);
+        path = pathbuf = g_strdup_printf("%s/qemu-socket-XXXXXX",
+                                         g_get_tmp_dir());
     }
 
     pathlen = strlen(path);
-- 
2.34.1


Re: [PATCH v3 11/26] util/qemu-sockets: Use g_get_tmp_dir() to get the directory for temporary files
Posted by Philippe Mathieu-Daudé 3 years, 3 months ago
On 20/10/22 13:51, Alex Bennée wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> Replace the existing logic to get the directory for temporary files
> with g_get_tmp_dir(), which works for win32 too.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Message-Id: <20221006151927.2079583-4-bmeng.cn@gmail.com>
> ---
>   util/qemu-sockets.c | 5 ++---
>   1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
> index 83f4bd6fd2..0c41ca9e42 100644
> --- a/util/qemu-sockets.c
> +++ b/util/qemu-sockets.c
> @@ -919,9 +919,8 @@ static int unix_listen_saddr(UnixSocketAddress *saddr,
>       if (saddr->path[0] || abstract) {
>           path = saddr->path;
>       } else {
> -        const char *tmpdir = getenv("TMPDIR");
> -        tmpdir = tmpdir ? tmpdir : "/tmp";
> -        path = pathbuf = g_strdup_printf("%s/qemu-socket-XXXXXX", tmpdir);
> +        path = pathbuf = g_strdup_printf("%s/qemu-socket-XXXXXX",
> +                                         g_get_tmp_dir());

IIUC this code is not reachable on win32; anyhow using g_get_tmp_dir()
is a good cleanup for the codebase.

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>