From nobody Mon May 6 17:01:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 150703355093454.27324222348932; Tue, 3 Oct 2017 05:25:50 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ACBD1C04AC7B; Tue, 3 Oct 2017 12:25:49 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6A9355C1A1; Tue, 3 Oct 2017 12:25:49 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1CC211806106; Tue, 3 Oct 2017 12:25:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v93C7NoE004580 for ; Tue, 3 Oct 2017 08:07:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7995660E3B; Tue, 3 Oct 2017 12:07:23 +0000 (UTC) Received: from mamuti.net (ovpn-204-116.brq.redhat.com [10.40.204.116]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4B41C6025A for ; Tue, 3 Oct 2017 12:07:21 +0000 (UTC) Received: by mamuti.net (Postfix, from userid 500) id 1829E10174C; Tue, 3 Oct 2017 14:07:20 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com ACBD1C04AC7B Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Jiri Denemark To: libvir-list@redhat.com Date: Tue, 3 Oct 2017 14:07:18 +0200 Message-Id: <1a354c249991187577ceb27de90cd974b230a076.1507032438.git.jdenemar@redhat.com> Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] tests: Do not ignore mode parameter in mocked open() X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 03 Oct 2017 12:25:50 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Luyao Huang This is normally not an issue since the tests which use mocked open() do not create files. But once coverage build is enabled, gcov_open will use O_CREATE and real_open will read random data rather than the actual mode argument. Signed-off-by: Jiri Denemark --- tests/virfilewrapper.c | 13 ++++++++++++- tests/virusbmock.c | 15 ++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/tests/virfilewrapper.c b/tests/virfilewrapper.c index fede7b2e89..1d1d182708 100644 --- a/tests/virfilewrapper.c +++ b/tests/virfilewrapper.c @@ -257,10 +257,21 @@ int open(const char *path, int flags, ...) { int ret =3D -1; char *newpath =3D NULL; + va_list ap; + mode_t mode =3D 0; =20 PATH_OVERRIDE(newpath, path); =20 - ret =3D real_open(newpath, flags); + /* The mode argument is mandatory when O_CREAT is set in flags, + * otherwise the argument is ignored. + */ + if (flags & O_CREAT) { + va_start(ap, flags); + mode =3D va_arg(ap, mode_t); + va_end(ap); + } + + ret =3D real_open(newpath, flags, mode); =20 VIR_FREE(newpath); =20 diff --git a/tests/virusbmock.c b/tests/virusbmock.c index 8d60664944..f430a2edad 100644 --- a/tests/virusbmock.c +++ b/tests/virusbmock.c @@ -87,13 +87,26 @@ int open(const char *pathname, int flags, ...) { char *path; int ret; + va_list ap; + mode_t mode =3D 0; =20 init_syms(); =20 path =3D get_fake_path(pathname); if (!path) return -1; - ret =3D realopen(path, flags); + + /* The mode argument is mandatory when O_CREAT is set in flags, + * otherwise the argument is ignored. + */ + if (flags & O_CREAT) { + va_start(ap, flags); + mode =3D va_arg(ap, mode_t); + va_end(ap); + } + + ret =3D realopen(path, flags, mode); + VIR_FREE(path); return ret; } --=20 2.14.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list