From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37218) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZXxTr-0000hf-BB for qemu-devel@nongnu.org; Fri, 04 Sep 2015 16:21:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZXxTp-0001tN-W1 for qemu-devel@nongnu.org; Fri, 04 Sep 2015 16:21:03 -0400 References: <5527b250be7e2ce3359680b31f8c431924299a95.1440171025.git.DirtY.iCE.hu@gmail.com> From: Eric Blake Message-ID: <55E9FD26.4060208@redhat.com> Date: Fri, 4 Sep 2015 14:20:54 -0600 MIME-Version: 1.0 In-Reply-To: <5527b250be7e2ce3359680b31f8c431924299a95.1440171025.git.DirtY.iCE.hu@gmail.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="RrVAQte3xI5JMFAa9sJEDte4gpWuMB0h9" Subject: Re: [Qemu-devel] [PATCH v2 01/49] opts: produce valid command line in qemu_opts_print List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?B?S8WRdsOhZ8OzLCBab2x0w6Fu?= , qemu-devel@nongnu.org Cc: Kevin Wolf , Gerd Hoffmann , "open list:Block layer core" This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --RrVAQte3xI5JMFAa9sJEDte4gpWuMB0h9 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 08/21/2015 09:36 AM, K=C5=91v=C3=A1g=C3=B3, Zolt=C3=A1n wrote: > This will let us print options in a format that the user would actually= > write it on the command line (foo=3Dbar,baz=3Dasd,etc=3Ddef), without > prepending a spurious comma at the beginning of the list, or quoting > values unnecessarily. This patch provides the following changes: > * write id=3D, if the option has an id > * do not print separator before the first element > * do not quote string arguments > * properly escape commas (,) for QEMU >=20 > Reviewed-by: Markus Armbruster > Reviewed-by: Stefan Hajnoczi > Reviewed-by: Marc-Andr=C3=A9 Lureau > Signed-off-by: K=C5=91v=C3=A1g=C3=B3, Zolt=C3=A1n > --- > +++ b/util/qemu-option.c > @@ -730,14 +730,35 @@ void qemu_opts_del(QemuOpts *opts) > g_free(opts); > } > =20 > -void qemu_opts_print(QemuOpts *opts, const char *sep) > +/* print value, escaping any commas in value */ > +static void escaped_print(const char *value) > +{ > + const char *ptr; > + > + for (ptr =3D value; *ptr; ++ptr) { > + if (*ptr =3D=3D ',') { > + putchar(','); > + } > + putchar(*ptr); > + } I guess this not in a hot path. (If it were, I might suggest using strchr() to skip to the next command, and fwrite() to output blocks of data between commas, rather than putchar() at a time; but unless it shows up in a benchmark that might be premature optimization) --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --RrVAQte3xI5JMFAa9sJEDte4gpWuMB0h9 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/ iQEcBAEBCAAGBQJV6f0mAAoJEKeha0olJ0NqIYgH/2iF08jL+K26cs+JeKCe4C7h NGcE+G+NyHMcquLnhyLgLL9ijA5tURhABb+Ibao0dDAP3RGZZmUg3TjOwZ1W+DTL YBb6TDUFFZjprJnEmOS909uUOhKU5pMrTMoOcxPT/mn+2IuzULukp/B4ORaoNE7L 9sCNUjisRLOSoK+c1mCbM+qj3ACUJiUo7YTcWvRaBjfnGkNLHzn+gE8TePqMvRDj JMPVzcXKSwt1m6LRn8axGXBTCxpzuZdKMUFmFTys5sPVA+NtgbntWlRzEUxLpa7G b+W8ha/t2p7t1hWGxNGoM26T4V1skCuAugVEkbkW1EVYA96tE5RuSExtsPME63M= =pnXw -----END PGP SIGNATURE----- --RrVAQte3xI5JMFAa9sJEDte4gpWuMB0h9--