From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36151) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aKDoI-0006c3-IE for qemu-devel@nongnu.org; Fri, 15 Jan 2016 18:29:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aKDoF-0001Zw-Be for qemu-devel@nongnu.org; Fri, 15 Jan 2016 18:29:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58673) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aKDoF-0001Zl-4S for qemu-devel@nongnu.org; Fri, 15 Jan 2016 18:29:35 -0500 References: <1452603559-13685-1-git-send-email-berrange@redhat.com> From: Eric Blake Message-ID: <569980DC.5030707@redhat.com> Date: Fri, 15 Jan 2016 16:29:32 -0700 MIME-Version: 1.0 In-Reply-To: <1452603559-13685-1-git-send-email-berrange@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="0h2Gv234eTAqGGlLIehc2f6eAdQdENWlf" Subject: Re: [Qemu-devel] [PATCH v2] s390: use FILE instead of QEMUFile for creating text file List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" , qemu-devel@nongnu.org Cc: Cornelia Huck , Richard Henderson This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --0h2Gv234eTAqGGlLIehc2f6eAdQdENWlf Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 01/12/2016 05:59 AM, Daniel P. Berrange wrote: > The s390 skeys monitor command needs to write out a plain text > file. Currently it is using the QEMUFile class for this, but > work is ongoing to refactor QEMUFile and eliminate much code > related to it. The only feature qemu_fopen() gives over fopen() > is support for QEMU FD passing, but this can be achieved with > qemu_open() + fdopen() too. Switching to regular stdio FILE > APIs avoids the need to sprintf via an intermedia buffer which s/intermedia/intermediate/ > slightly simplifies the code. >=20 > Signed-off-by: Daniel P. Berrange > --- > hw/s390x/s390-skeys.c | 26 ++++++++++++++------------ > 1 file changed, 14 insertions(+), 12 deletions(-) >=20 > @@ -124,8 +120,14 @@ void qmp_dump_skeys(const char *filename, Error **= errp) > return; > } > =20 > - f =3D qemu_fopen(filename, "wb"); > + fd =3D qemu_open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0600); A strict conversion should probably include O_BINARY for mingw (where "wb" turns on binary mode). But maybe we should just make qemu_open() itself _always_ provide O_BINARY so that callers don't have to worry about it - do we really have a reason to open a file on mingw where we want \r\n munged into \n due to text mode? > + if (fd < 0) { > + error_setg_file_open(errp, errno, filename); > + return; > + } > + f =3D fdopen(fd, "wb"); > if (!f) { > + close(fd); > error_setg_file_open(errp, errno, filename); close() may corrupt errno, resulting in a report of the wrong message. Swap these two lines. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --0h2Gv234eTAqGGlLIehc2f6eAdQdENWlf Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJWmYDcAAoJEKeha0olJ0Nqr2cIAKjt/pwp3IOXrHOU2g1rrW2y knl776bhnMpNiDcmV1VD76F5CRu4HTi5dCjBWjgXhl3Syl7wTjiGTAMPksgZFnoi ak7TGV/88zLrimKXeJaBeoX8YdsvQuoBIGn+LEM2JC+M1sHU2xGRLSIoDyaUAlDc fIx3YuYv+q2bJz2LbTMsibb3lLRAvz3yuaJi+yW4Xx7W+vcbZhCqiRqBATaiRN6r 6TIoV2cqC8UbBIl1JUcq7bKQmma8lm7Erv45RhspTse1Y+wyhzVn4zdpbD/gt83F wzGB4QFZMcJ+Ov9K2GZgsh+9q6TOLeUnl7h08o/gJQG7wWKrON3pBAYCS2zn9cU= =N8uX -----END PGP SIGNATURE----- --0h2Gv234eTAqGGlLIehc2f6eAdQdENWlf--