From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2D1E2ECAAD8 for ; Thu, 22 Sep 2022 19:42:42 +0000 (UTC) Received: from localhost ([::1]:51694 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1obS5o-0000u2-Rh for qemu-devel@archiver.kernel.org; Thu, 22 Sep 2022 15:42:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48596) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1obS2P-0005Si-6v; Thu, 22 Sep 2022 15:39:11 -0400 Received: from mail-lj1-x22d.google.com ([2a00:1450:4864:20::22d]:45808) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1obS2J-0004Mi-4X; Thu, 22 Sep 2022 15:39:04 -0400 Received: by mail-lj1-x22d.google.com with SMTP id c7so12199922ljm.12; Thu, 22 Sep 2022 12:39:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=qOf0DmlC18b0/UTyI2J7fjeyg6ra5SB1/TQ9Ft5bD7w=; b=E4KmuHaeFQsWSqIZdBJJvvDKeRalgS5VopVRIhK9VSBozPvxu0KgiM2v3InDRyAub4 QWmzCj6yAlZvIRFP2lPCUqzDuN+zCQzhiKWFBZj5ljEirI2U01cPaHo7dDLjB1XQZquF pKfNouOWiT9dLnVfM9Gh3uxe5IP1OfaK3Zt0VcsskhSykTZgS2x+ody4sw0vTqcm4/bv UdzIUO5/KyQnJmbuKctWHFsAFE5NjdJJoVJkyy7J0LkJdQQ/rHpHjbGZZEFDfdGuuM0y vqCeGZbohpWrQDk/8g0NotB4NN2ADKUwhJfZmxiDIMcQjZCU26z2P1scCLHW1qYH/Dpo aUvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=qOf0DmlC18b0/UTyI2J7fjeyg6ra5SB1/TQ9Ft5bD7w=; b=NR4CbCS1uRKxKYUysTTaQpvLwMI0pSEeUSY0EgKmCVC77oVZuc/rLTpA6DiMmVYz6r IxToK2LEoiRWEHeb8IklxIniwRWT4jl3Y7SICpCnh95OA/4TciqcjC/QAbSpza6+cJrS +czxagiEbfIWFkxa59lowR3/UKcRBj8dU5VgJwgFjsxVwxL62ARck0vBAdJ2LxRagF/o JmE+7mcO00l5jBXwZdc5OP9+SBrguwjVwmZbdVBKHeGtppAdbA5AD9Vbe9heFyzQf1NW we7rKkDyzycDOf/JF8LQzC2eHVbbEo4ZN6nPeA01FcjVjinFiEnkhKmt7vjfXr2/2eDS Y44g== X-Gm-Message-State: ACrzQf3X4tnVmjfAbT/1teX/9WfzeSUg7QLy0R+dEJICecL6FL4SLRy+ VzKWePMmjmGKWu9Oa1dZcNy4A5tVqSRCiK0b9NM= X-Google-Smtp-Source: AMsMyM4zAKfhhhA7CdG7cxPq/RoI/2RZyAmvEQ6JAyn53NlCysofeWYLpREAWM5ReLckUlPD2v0WtW7YtWBiY7WffAY= X-Received: by 2002:a2e:a44c:0:b0:26b:e70f:a026 with SMTP id v12-20020a2ea44c000000b0026be70fa026mr1648483ljn.94.1663875541107; Thu, 22 Sep 2022 12:39:01 -0700 (PDT) MIME-Version: 1.0 References: <20220920103159.1865256-1-bmeng.cn@gmail.com> <20220920103159.1865256-4-bmeng.cn@gmail.com> In-Reply-To: <20220920103159.1865256-4-bmeng.cn@gmail.com> From: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= Date: Thu, 22 Sep 2022 21:38:49 +0200 Message-ID: Subject: Re: [PATCH v2 03/39] block: Unify the get_tmp_filename() implementation To: Bin Meng Cc: qemu-devel@nongnu.org, Bin Meng , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org Content-Type: multipart/alternative; boundary="00000000000094081e05e94936eb" Received-SPF: pass client-ip=2a00:1450:4864:20::22d; envelope-from=marcandre.lureau@gmail.com; helo=mail-lj1-x22d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" --00000000000094081e05e94936eb Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi On Tue, Sep 20, 2022 at 2:17 PM Bin Meng wrote: > From: Bin Meng > > At present get_tmp_filename() has platform specific implementations > to get the directory to use for temporary files. Switch over to use > g_get_tmp_dir() which works on all supported platforms. > > As discussed in v1, there are other things to do while touching this code. And since it is optional for the series goal, please send this as a different patch/series. > Signed-off-by: Bin Meng > --- > > (no changes since v1) > > block.c | 16 ++-------------- > 1 file changed, 2 insertions(+), 14 deletions(-) > > diff --git a/block.c b/block.c > index bc85f46eed..d06df47f72 100644 > --- a/block.c > +++ b/block.c > @@ -864,21 +864,10 @@ int bdrv_probe_geometry(BlockDriverState *bs, > HDGeometry *geo) > */ > int get_tmp_filename(char *filename, int size) > { > -#ifdef _WIN32 > - char temp_dir[MAX_PATH]; > - /* GetTempFileName requires that its output buffer (4th param) > - have length MAX_PATH or greater. */ > - assert(size >=3D MAX_PATH); > - return (GetTempPath(MAX_PATH, temp_dir) > - && GetTempFileName(temp_dir, "qem", 0, filename) > - ? 0 : -GetLastError()); > -#else > int fd; > const char *tmpdir; > - tmpdir =3D getenv("TMPDIR"); > - if (!tmpdir) { > - tmpdir =3D "/var/tmp"; > - } > + tmpdir =3D g_get_tmp_dir(); > + > if (snprintf(filename, size, "%s/vl.XXXXXX", tmpdir) >=3D size) { > return -EOVERFLOW; > } > @@ -891,7 +880,6 @@ int get_tmp_filename(char *filename, int size) > return -errno; > } > return 0; > -#endif > } > > /* > -- > 2.34.1 > > > --=20 Marc-Andr=C3=A9 Lureau --00000000000094081e05e94936eb Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi

On Tue, Sep 20, 2022 at 2:17 PM Bin= Meng <bmeng.cn@= gmail.com> wrote:
From: Bin Meng <bin.meng@windriver.com>

At present get_tmp_filename() has platform specific implementations
to get the directory to use for temporary files. Switch over to use
g_get_tmp_dir() which works on all supported platforms.


As discussed in v1, there are other th= ings to do while touching this code. And since it is optional for the serie= s goal, please send this as a different patch/series.

<= div>=C2=A0
Signed-off-by: Bin Meng <bin.meng@windriver.com>
---

(no changes since v1)

=C2=A0block.c | 16 ++--------------
=C2=A01 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/block.c b/block.c
index bc85f46eed..d06df47f72 100644
--- a/block.c
+++ b/block.c
@@ -864,21 +864,10 @@ int bdrv_probe_geometry(BlockDriverState *bs, HDGeome= try *geo)
=C2=A0 */
=C2=A0int get_tmp_filename(char *filename, int size)
=C2=A0{
-#ifdef _WIN32
-=C2=A0 =C2=A0 char temp_dir[MAX_PATH];
-=C2=A0 =C2=A0 /* GetTempFileName requires that its output buffer (4th para= m)
-=C2=A0 =C2=A0 =C2=A0 =C2=A0have length MAX_PATH or greater.=C2=A0 */
-=C2=A0 =C2=A0 assert(size >=3D MAX_PATH);
-=C2=A0 =C2=A0 return (GetTempPath(MAX_PATH, temp_dir)
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 && GetTempFileName(temp_= dir, "qem", 0, filename)
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ? 0 : -GetLastError());
-#else
=C2=A0 =C2=A0 =C2=A0int fd;
=C2=A0 =C2=A0 =C2=A0const char *tmpdir;
-=C2=A0 =C2=A0 tmpdir =3D getenv("TMPDIR");
-=C2=A0 =C2=A0 if (!tmpdir) {
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 tmpdir =3D "/var/tmp";
-=C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 tmpdir =3D g_get_tmp_dir();
+
=C2=A0 =C2=A0 =C2=A0if (snprintf(filename, size, "%s/vl.XXXXXX", = tmpdir) >=3D size) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return -EOVERFLOW;
=C2=A0 =C2=A0 =C2=A0}
@@ -891,7 +880,6 @@ int get_tmp_filename(char *filename, int size)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return -errno;
=C2=A0 =C2=A0 =C2=A0}
=C2=A0 =C2=A0 =C2=A0return 0;
-#endif
=C2=A0}

=C2=A0/*
--
2.34.1




--
Marc-Andr= =C3=A9 Lureau
--00000000000094081e05e94936eb--