From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:55619) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RqBcr-0004mM-Nd for qemu-devel@nongnu.org; Wed, 25 Jan 2012 17:47:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RqBcp-0006fd-SG for qemu-devel@nongnu.org; Wed, 25 Jan 2012 17:47:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:32305) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RqBcp-0006fM-KE for qemu-devel@nongnu.org; Wed, 25 Jan 2012 17:47:31 -0500 Message-ID: <4F20867F.3090705@redhat.com> Date: Wed, 25 Jan 2012 15:47:27 -0700 From: Eric Blake MIME-Version: 1.0 References: <1327530211-25614-1-git-send-email-ronniesahlberg@gmail.com> <1327530211-25614-2-git-send-email-ronniesahlberg@gmail.com> In-Reply-To: <1327530211-25614-2-git-send-email-ronniesahlberg@gmail.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enig1C468C3D5CDC1F62282BCFDA" Subject: Re: [Qemu-devel] [PATCH] READCONFIG: Allow reading the configuration from a pre-existing filedescriptor List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Ronnie Sahlberg Cc: qemu-devel@nongnu.org This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig1C468C3D5CDC1F62282BCFDA Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 01/25/2012 03:23 PM, Ronnie Sahlberg wrote: > Update the readconfig filename parsing to allow specifying an existing,= inherited, filedescriptor as 'fd:' > This is useful when you want to pass potentially sensitive onfiguration= data to qemu without having it hit the filesystem/stable-storage >=20 > Signed-off-by: Ronnie Sahlberg > --- > qemu-config.c | 15 +++++++++++++-- > qemu-options.hx | 3 ++- > 2 files changed, 15 insertions(+), 3 deletions(-) Reviewed-by: Eric Blake >=20 > diff --git a/qemu-config.c b/qemu-config.c > index b030205..c12c5eb 100644 > --- a/qemu-config.c > +++ b/qemu-config.c > @@ -770,8 +770,19 @@ out: > =20 > int qemu_read_config_file(const char *filename) > { > - FILE *f =3D fopen(filename, "r"); > - int ret; > + FILE *f; > + int ret, fd; > + > + if (strncmp(filename, "fd:", 3)) { > + f =3D fopen(filename, "r"); > + } else { > + errno =3D 0; > + fd =3D strtol(filename + 3, NULL, 10); This means -readconfig fd:4junk will read fd 4. I don't know if there is a policy on ignoring vs. rejecting ill-formed command line, which is why I'm okay with the patch as-is if it meets project policy; but you might want to consider passing a non-NULL pointer for the second argument and rejecting an empty string or trailing junk. > + if (errno !=3D 0) { > + return -errno; > + } POSIX says that strtol("", NULL, 10) may return 0 without setting errno (that is, you can't rely on EINVAL in that case). That's another argument for _always_ passing a non-NULL pointer and to see if you accidentally parsed an empty string, since you don't want to have another FILE* competing with stdin. [Libvirt forbids the direct use of strtol and friends, and instead provides wrapper functions that take care of the sanity checking that is not mandated by POSIX; it may be worth introducing a qemu_strtol that does likewise, but that's a different cleanup project with wider scope.] --=20 Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --------------enig1C468C3D5CDC1F62282BCFDA Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBCAAGBQJPIIaAAAoJEKeha0olJ0NqPckH/1g/bZcpo4xeXmJE5fxsXbB7 b0TRSgfeZCpgYPOXWsk4ibSqa6UK7mzqaQ9h57dP8F44mqauntnWqKlbeBO5PDQn adkvIiAvnfoA70ES34VkJ4SGsK3Tj3rwfnmtQwDzfj+clDncdgI1ejiWmew6PuLR aGnZD4emjU55nrDqqYjaSYryWwQXZMQ45JYqXvmkupiCt63U2hPjwFYvFqm0+taX Y6sCqbBkptsZyFcCzWh0kDMlr1CduS/lAPVlRTyvWUdnxhTQSoQVPBXsHEXp35ba ZAbaA3WMM0JvRw7fXGYE4FLazQCVT3iumq+JUMrbpSgEwvE7nadWHWf6UgJU80o= =GIEi -----END PGP SIGNATURE----- --------------enig1C468C3D5CDC1F62282BCFDA--