From nobody Mon Feb 9 19:07:49 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1664107093; cv=none; d=zohomail.com; s=zohoarc; b=N23i4rALF4rbG9DN7q2SyxYW5PAUaoHKTCXmPriQ2hVOQ0NP0Qp5TydXCAfDx+j0P9QTrpvvYiV2SK1WyW6BjzFuAgfhZJNvX6zo1W2vKcUvEJf7a1bJTxp6C1/qtgR/r427CzzhuiMJSH0hb85fT+EiBbUPDxEPDg9gI12lKxg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664107093; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wj7NFE4UEqf1bXdPeQ070iFkhBShBJOjWt5P85H+XeI=; b=BNOkSU2VAr4FUDNg6iv7msAP6I5gFsi3nXBQ3I8/cCeqLGNu0kItNNPGy8lHavW2yEvoAVrVrZL/Ax/IfKkXwgVa9TsLbemBoIUJVlogqaudxZvc+bE4fg+MR5Is9zGx0uUL9u/QPlouLPNJm68szPXU/qn8sWDGotb9LFrECNM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 166410709332830.883737214732378; Sun, 25 Sep 2022 04:58:13 -0700 (PDT) Received: from localhost ([::1]:38566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ocQGy-00083N-8r for importer@patchew.org; Sun, 25 Sep 2022 07:58:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55922) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ocPrD-0002ia-Tv for qemu-devel@nongnu.org; Sun, 25 Sep 2022 07:31:36 -0400 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]:42593) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ocPr3-0006KO-RT for qemu-devel@nongnu.org; Sun, 25 Sep 2022 07:31:28 -0400 Received: by mail-pg1-x531.google.com with SMTP id t190so4208012pgd.9 for ; Sun, 25 Sep 2022 04:31:15 -0700 (PDT) Received: from ubuntu.. (144.168.56.201.16clouds.com. [144.168.56.201]) by smtp.gmail.com with ESMTPSA id z4-20020a1709027e8400b00176c6738d13sm9187760pla.169.2022.09.25.04.31.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Sep 2022 04:31:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=wj7NFE4UEqf1bXdPeQ070iFkhBShBJOjWt5P85H+XeI=; b=G9koeUdrjJZrYH2/Ca1dkiSWRbpTJqAwlZb30pYM6dopeGaOMDCUEPs124Ui/H6ii4 L+Q2YWqhlUOUtlTdtd+apOOzeFgmPU+irSPwCVINPPj9wv8t27yKHeYh+b/HptVt7s9T 9vEwaCjYaEy51JNpOyWZx/+2dQkBfMbAAlyTRc0FxTVThrx+jEVhu2D9bwZTbJzh8zSj 2FAmeorrbeUAe1fsM59Wz6t91JQ0fhjPAbjz0OWJW/RGdPPsqHgeKrYruISWJ2q9Lngm +l/Iz7jCgmc/mgC3qWQwwEuwFTCAsSsHGa5Qe7088U2BgF/46oSWgvIu79IdNtpbOpQi CVYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=wj7NFE4UEqf1bXdPeQ070iFkhBShBJOjWt5P85H+XeI=; b=AGw7jP+O6tNe1rkY6pByW3It9leb/M9nBrQl6iMlVN8nMbTnkqqk1gS6GjNn7jyqSh pXt4EG2vMN9T/BWRjcjCJCXcIjL2M7s9UkKW/RfK/6XnL5qaTxQLz0VV5RGUy2+IJcsk 4ym/FwpxxQGw4CbBEhUoiQPnYMTr9MiVrdMlAoiwRANV4EZMMZzSQ7psWqF8sf76qHO0 l60AFU9BmO3GBmKvMy05Hyf2Hijx5rLbaMTHEcU/+sDPOTAYNR4AZaHgHxtUPlAzKtUL I737EWooN0szoR/uuMgtvKHTnsiLqblhB5Fu53vATxqqKU/BeqYNY9NNqIWEv3TNRGeR Sycw== X-Gm-Message-State: ACrzQf3cvLfQuILST/jvOaIOgfYKEskneGdg+p7QMQZkc9TgonRJz9iv ge1jyA5oyQfMiQAKcP4EzuvaMiRM2Ds= X-Google-Smtp-Source: AMsMyM47LSROCIetAPTVF/+L8i72Uf/hK9p7yfvfyMuct7Trnop1goAV/gPyjOJ9UoU1Cv4Rd+Rb5Q== X-Received: by 2002:a63:1508:0:b0:438:eb90:52d1 with SMTP id v8-20020a631508000000b00438eb9052d1mr15639271pgl.252.1664105474639; Sun, 25 Sep 2022 04:31:14 -0700 (PDT) From: Bin Meng To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Bin Meng , Laurent Vivier , Paolo Bonzini , Thomas Huth Subject: [PATCH v3 12/54] tests/qtest: hd-geo-test: Avoid using hardcoded /tmp Date: Sun, 25 Sep 2022 19:29:50 +0800 Message-Id: <20220925113032.1949844-13-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220925113032.1949844-1-bmeng.cn@gmail.com> References: <20220925113032.1949844-1-bmeng.cn@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::531; envelope-from=bmeng.cn@gmail.com; helo=mail-pg1-x531.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, 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1664107094584100001 Content-Type: text/plain; charset="utf-8" From: Bin Meng This case was written to use hardcoded /tmp directory for temporary files. Update to use g_file_open_tmp() for a portable implementation. Signed-off-by: Bin Meng Reviewed-by: Marc-Andr=C3=A9 Lureau --- Changes in v3: - Split to a separate patch - Ensure g_autofree variable is initialized - Use g_steal_pointer() in create_test_img() tests/qtest/hd-geo-test.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/tests/qtest/hd-geo-test.c b/tests/qtest/hd-geo-test.c index 413cf964c0..455bc5db5c 100644 --- a/tests/qtest/hd-geo-test.c +++ b/tests/qtest/hd-geo-test.c @@ -27,20 +27,19 @@ =20 static char *create_test_img(int secs) { - char *template =3D strdup("/tmp/qtest.XXXXXX"); + g_autofree char *template =3D NULL; int fd, ret; =20 - fd =3D mkstemp(template); + fd =3D g_file_open_tmp("qtest.XXXXXX", &template, NULL); g_assert(fd >=3D 0); ret =3D ftruncate(fd, (off_t)secs * 512); close(fd); =20 if (ret) { - free(template); template =3D NULL; } =20 - return template; + return g_steal_pointer(&template); } =20 typedef struct { @@ -422,9 +421,8 @@ static MBRpartitions empty_mbr =3D { {false, 0, 0, 0, 0= , 0, 0, 0, 0}, =20 static char *create_qcow2_with_mbr(MBRpartitions mbr, uint64_t sectors) { - const char *template =3D "/tmp/qtest.XXXXXX"; - char *raw_path =3D strdup(template); - char *qcow2_path =3D strdup(template); + g_autofree char *raw_path =3D NULL; + char *qcow2_path; char cmd[100 + 2 * PATH_MAX]; uint8_t buf[512] =3D {}; int i, ret, fd, offset; @@ -468,7 +466,7 @@ static char *create_qcow2_with_mbr(MBRpartitions mbr, u= int64_t sectors) offset +=3D 0x10; } =20 - fd =3D mkstemp(raw_path); + fd =3D g_file_open_tmp("qtest.XXXXXX", &raw_path, NULL); g_assert(fd >=3D 0); close(fd); =20 @@ -478,7 +476,7 @@ static char *create_qcow2_with_mbr(MBRpartitions mbr, u= int64_t sectors) g_assert(ret =3D=3D sizeof(buf)); close(fd); =20 - fd =3D mkstemp(qcow2_path); + fd =3D g_file_open_tmp("qtest.XXXXXX", &qcow2_path, NULL); g_assert(fd >=3D 0); close(fd); =20 @@ -506,7 +504,6 @@ static char *create_qcow2_with_mbr(MBRpartitions mbr, u= int64_t sectors) free(qemu_img_abs_path); =20 unlink(raw_path); - free(raw_path); =20 return qcow2_path; } @@ -714,7 +711,7 @@ static void test_override(TestArgs *args, CHSResult exp= ected[]) =20 for (i =3D 0; i < args->n_drives; i++) { unlink(args->drives[i]); - free(args->drives[i]); + g_free(args->drives[i]); } g_free(args->drives); g_strfreev(args->argv); @@ -867,7 +864,7 @@ static void test_override_scsi_hot_unplug(void) =20 for (i =3D 0; i < args->n_drives; i++) { unlink(args->drives[i]); - free(args->drives[i]); + g_free(args->drives[i]); } g_free(args->drives); g_strfreev(args->argv); @@ -927,7 +924,7 @@ static void test_override_virtio_hot_unplug(void) =20 for (i =3D 0; i < args->n_drives; i++) { unlink(args->drives[i]); - free(args->drives[i]); + g_free(args->drives[i]); } g_free(args->drives); g_strfreev(args->argv); @@ -987,7 +984,7 @@ test_add_done: for (i =3D 0; i < backend_last; i++) { if (img_file_name[i]) { unlink(img_file_name[i]); - free(img_file_name[i]); + g_free(img_file_name[i]); } } =20 --=20 2.34.1